user2029145
user2029145

Reputation: 5

Implementing API into Python program

I am using Requests to communicate with a simple api.

The code looks like this:

payload = {'text': reply, 'name': varname, 'avatar': varavatar}
r = requests.get('http://example.de/create.json', params=payload)

However, the result looks like this:

{"result": "error", "error": "error_no_direct_connection"}

This might be a problem with the api but I'm not sure. So I printed out the URL that Requests created (print r.url). It looks like this: http://url.com/create.json?text=Test&name=myname&avatar=http%3A%2F%2Fa0.url.com%2Fnormal.png

To make sure it's not a problem oft the api I tried it with curl. The command works!

curl --data-urlencode "text=Test" -d "name=myname" -d "avatar=http://url.com/normal.png" http://url.com/create.json

Upvotes: 0

Views: 102

Answers (1)

Martin v. Löwis
Martin v. Löwis

Reputation: 127447

The curl option --data causes curl to submit a POST request, not a GET request. Try request.post(..., data=...).

Upvotes: 1

Related Questions