1

I am trying to wrap my head around the Imgur API. I have found some good examples of how to send the authorization header to Imgur, however they all use urllib2, and I apparently, using pyhton 3.4.1 can only use urllib3.

So I have tried a couple of things and none of them seem to be working.

from this post I tried using the basic_auth header:

http = urllib3.PoolManager()
header = urllib3.make_headers(basic_auth="Client-ID" + CLIENT_ID)
r = http.request('GET', 'https://api.imgur.com/3/gallery/r/pics', headers=header)

that gives me a 403 error.

from this post I tried this method instead:

http = urllib3.PoolManager()
header= {"Content-Type": "text", "Authorization": "Client-ID" + CLIENT_ID}
r = http.request('GET', 'https://api.imgur.com/3/gallery/r/pics', headers=header)

that also returns a 403.

Now however I have got a step closer by reading the urllib3 documents and tried sending the Authorization as a field instead.

http = urllib3.PoolManager()
r = http.request('GET', 'https://api.imgur.com/3/gallery/r/pics', fields={"Authorization": "Client-ID " + CLIENT_ID})

this however returns a 401.

so can some one help me to figure out basic anonymous interaction with the Imgur API using these, or other methods?

Community
  • 1
  • 1
sec_goat
  • 1,272
  • 1
  • 12
  • 20

1 Answers1

2

Per imgur's API documentation, you have to send the auth header as such:

Authorization: Client-ID YOUR_CLIENT_ID

In this line:

header = urllib3.make_headers(basic_auth="Client-ID" + CLIENT_ID)

you are sending it as: Authorization: Client-IDYOUR_CLIENT_ID

You need a space between.

scandinavian_
  • 2,496
  • 1
  • 17
  • 19
  • unfortunately that gives me the exact same 403 response. However if I use the second example, with a space i get a 200! I fell very silly for it only being a space that was causing my issue! – sec_goat May 29 '14 at 16:47