Reputation: 1396
I am trying to convert a Curl command into Python3. But I am having issues inserting the header lines and sending the post request. The command is supposed to send a post request and print the formatted response.
This is the command syntax:
curl -s 'https://api.sandbox.ebay.com/ws/api.dll'\
-H 'X-EBAY-API-SITEID: 0'\
-H 'X-EBAY-API-COMPATIBILITY-LEVEL: 861'\
--data '<?xml version="1.0" encoding="utf-8"?>
<GetCategoriesRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<LevelLimit>1</LevelLimit>
</GetCategoriesRequest>' | xmllint --format -
This is the code I have in the python version, I am missing the data, I think I need to use request.post but am really having a bad time translating the command.
import requests
url = 'https://api.sandbox.ebay.com/ws/api.dll'
headers = { 'X-EBAY-API-SITEID': '0', 'X-EBAY-API-COMPATIBILITY-LEVEL': '861'}
r = requests.get(url, headers=headers)
Upvotes: 0
Views: 1605
Reputation: 171
You can send a post request using this code.
import requests
headers = {
'X-EBAY-API-SITEID': '0',
'X-EBAY-API-COMPATIBILITY-LEVEL': '861'
}
data = '<?xml version="1.0" encoding="utf-8"?><GetCategoriesRequest xmlns="urn:ebay:apis:eBLBaseComponents"> <LevelLimit>1</LevelLimit></GetCategoriesRequest>'
url = 'https://api.sandbox.ebay.com/ws/api.dll'
r = requests.post(url, headers=headers, data=data)
print r.content
Upvotes: 1