3

I am trying to convert a block of cURL to python requests. I get the following error when I do:

{'error': 'invalid_request', 'error_description': 'request is missing a required parameter or malformed.'}

What am I translating incorrectly?

curl

POST /identity/v1/oauth2/token HTTP/1.1
Host: api.sandbox.ebay.com
Authorization: Basic <B64-encoded-oauth-credentials>
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=<URL-decoded-auth-code>&redirect_uri=<your_redirect_uri>

my_call.py

headers = {
 'Content-Type': 'application/x-www-form-urlencoded',
a 'Authorization': f'Basic {<Base64 encoded value>}'
}
data = {
 'grant_type': 'authorization_code',
 'code': client_id # str,
 'redirect_uri': url # str,
 'scope': 'https://api.ebay.com/oauth/api_scope/sell.inventory.readonly',
}
def get_oath_token():
 url = 'https://api.ebay.com/identity/v1/oauth2/token'
 r = requests.post(url, headers=headers, data=data)
 print(r.json())
asked Mar 16, 2019 at 3:07
7
  • This may be too simple a fix, but is OAuth enabled? See this answer: stackoverflow.com/a/44689884/8787680 Commented Mar 16, 2019 at 4:16
  • How is the URL encoded? Does it look like (1) http://foo.bar/ or like (2) http%3A%2F%2Ffoo.bar%2F? Commented Mar 16, 2019 at 4:21
  • @SébastienLavoie I do have Oauth enabled Commented Mar 16, 2019 at 18:10
  • The url is like (1) Commented Mar 16, 2019 at 18:10
  • Can you try sending your POST request with the second version? You can do this by importing from requests.utils import quote and after defining url in the function get_oath_token, reassign it the following value: url = quote(url, safe=''). Commented Mar 16, 2019 at 18:27

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.