0

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)

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.