代码之家  ›  专栏  ›  技术社区  ›  juju

无法将cURL POST命令转换为python请求

  •  3
  • juju  · 技术社区  · 7 年前

    我试图将cURL块转换成python请求。执行此操作时,会出现以下错误:

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

    我翻译错了什么?

    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>
    

    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())
    
    0 回复  |  直到 7 年前