cURL XML POST works but not Python Requests - 3rd party Expert Rating API (w/ examples) -
i'm trying make post request sends xml data 3rd party server, works cmd line curl not python requests library (which need work). i've omitted out username, password, , domain urls. i'm using requests==2.2.1
curl example (works):
request:
$ curl --data '<?xml version="1.0" encoding="utf-8"?><request><authentication partnerid="12345" password="mypass1234" /><method name="gettestlist" /></request>' 'http://dev.expertrating.com/mydomain/webservices/' response:
<response><result name="gettestlist"><records><record test_id="6683" test_name="demo adobe photoshop cs3 test" coverage="layers ;type ;automating tasks , keyboard shortcuts ;workspace ;working images, retouching , transforming ;color management ;color , tonal adjustments ;using selection , drawing ;filters , saving images ;working web, video , animation" total_questions="10" duration="10" passing_marks="60" category="demo tests" /><record test_id="6684" test_name="demo programming c++ test" coverage="classes ;constructors ;variables , datatypes" total_questions="10" duration="10" passing_marks="60" category="demo tests" /><record test_id="6685" test_name="demo html 4.01 test" coverage="advanced tags ;fundamentals ;tags ;tables ;links , images ;forms , frames" total_questions="10" duration="10" passing_marks="60" category="demo tests" /><record test_id="6682" test_name="demo editing skills certification" coverage="prepositions ;parallel construction ;comma usage ;punctuation ;misplaced modifiers ;apostrophe usage ;sentence structure ;pronoun usage ;tenses ;article usage" total_questions="10" duration="10" passing_marks="60" category="demo tests" /></records></result></response> requests example: (fails) (via ipython/django)
ipython:
in [1]: import requests in [2]: payload = '<?xml version="1.0" encoding="utf-8"?><request><authentication partnerid="12345" password="mypass1234" /><method name="gettestlist" /></request>' in [3]: r = requests.post('http://dev.expertrating.com/mydomain/webservices/', data=payload, headers={'content-type': 'application/xml'}) in [4]: r.text out[4]: u"<?xml version='1.0' encoding='utf-8'?><response><error id='101' message='invalid request'><info>you have not posted valid request.</info></error></response>" am encoding requests string wrong? including wrong headers? literally copy/pasted urls , payload xml. tried posting urllib2 similar failing results.
any appreciated, in advance reads this.
it worked setting content-type header content-type: application/x-www-form-urlencoded instead of content-type: application/xml.
Comments
Post a Comment