user10437174
user10437174

Reputation:

Python - curl request - 'data-urlencode'

I would like to make a python query with this data but I can not convert the 'data-urlencode' interpretable for the python query.

It's my curl request :

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'

And this this my actual python request:

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)

I have trouble encoding the data to get the json. Thanks

Upvotes: 8

Views: 20989

Answers (1)

snd
snd

Reputation: 238

Isn't that curl command a GET request?

I'm not able to try your example but could you please try using the code below.

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()

Upvotes: 12

Related Questions