【问题标题】:Python - curl request - 'data-urlencode'Python - curl 请求 - 'data-urlencode'
【发布时间】:2019-06-21 14:48:51
【问题描述】:

我想用这些数据进行 python 查询,但我无法转换 python 查询可解释的“data-urlencode”。

这是我的 curl 请求:

    curl \
  --compressed \
  -H 'Accept-Encoding:gzip' \
  -H 'Accept-Language:fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7' \
  --get '**myurl**' \
    --data-urlencode 'app_code=xxxxxx' \
    --data-urlencode 'app_id=xxxxxx'

这是我实际的 python 请求:

import requests

headers = {
    'Accept-Encoding': 'gzip',
    'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
}

data = {
  'app_code': 'xxxxx',
  'app_id': 'xxxxx'
}

response = requests.post('https://places.cit.api.here.com/places/v1/autosuggest', headers=headers, data=data)

我无法对数据进行编码以获取 json。 谢谢

【问题讨论】:

    标签: python python-3.x curl python-requests


    【解决方案1】:

    那个 curl 命令不是 GET 请求吗?

    我无法尝试您的示例,但请您尝试使用下面的代码。

    import requests
    
    url = "https://places.cit.api.here.com/places/v1/autosuggest"
    
    h = {
    "Accept-Encoding":"gzip",
    "Accept-Language":"fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7"
    }
    params = {
    "app_code":"xxxxx",
    "app_id":"xxxxx"
    }
    
    r = request.get(url, headers=h, params=params).json()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 2018-05-26
      • 2022-01-07
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多