5

I'm using requests in Python 2.7 to try to change the description of a previously uploaded image using the API. In accordance with Imgur's API manual I used this:

r = requests.post('https://api.imgur.com/3/image/'+submission['id'], \
               headers={'Authorization':'Bearer '+access_token}, \
               data={'description':'blahblahblah'}, verify=False)

What I get in return is this:

{u'status': 200, u'data': False, u'success': True}

So, as far as I can see the OAUTH is working just fine, but the API itself is coming back "False" and the description doesn't get changed. I'm not finding any further guidance anywhere regarding this particular endpoint. Any ideas?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
FlaggFox
  • 51
  • 3
  • 3
    You have a `status` code of 200, and `success` is `True`, so as far as Imgur is concerned, your API call was successful. Whatever problems there may be from here on out, are with the Imgur API, *not* `requests` or Python, for that matter. – Martijn Pieters Feb 17 '13 at 21:12
  • 1
    The only thing that I could see you could do differently is to perhaps use the `.json` extension, so use `'https://api.imgur.com/3/image/{}.json'.format(submission['id'])` as the URL instead. – Martijn Pieters Feb 17 '13 at 21:15
  • Otherwise, take into account that Imgur GET responses are otherwise heavily cached, the result of setting a description could well be hidden for a while if cache results are still being served for a while. Clear your browser cache if you have to. – Martijn Pieters Feb 17 '13 at 21:18
  • 2
    Pro tip: the ``\`` backslashes are not needed to continue a Python statement across lines, when inside parenthesis. Python knows that you want to continue the statement already since it hasn't yet seen the balancing closing parethesis. – Martijn Pieters Feb 17 '13 at 21:27
  • @Martijn Pieters I didn't figure it was a requests or Python problem, I was just thinking I was missing something else. As far as the GET cache goes, I'm accessing it a number of ways and no update. The response from Imgur is kind of ambiguous, as it reponse with a "False", which, I guess could just mean "None" as well... Finally, adding .json at the end changed nothing. – FlaggFox Feb 17 '13 at 21:39
  • The `data` response is absolutely ambiguous, it is not documented at all what to expect in the `data` attribute here. But the `status` and the `success` entries are clear enough. As for cache, the *server* can also cache (and with a CDN, propagation is going to take a non-trivial amount of time too). – Martijn Pieters Feb 17 '13 at 21:42
  • Have you tried with a PUT instead of a POST. – karlcow Mar 07 '13 at 22:11
  • I tried your code, and I received `{"data":true,"success":true,"status":200}` as a result. In http://imgur.com/IMG-ID page, I can see changed title/desc. In http://USERNAME.imgur.com/all/ page, if I move mouse cursor over the picture, I can see changed title. But if click the image, I see old title. – falsetru Jun 24 '13 at 04:03

3 Answers3

0

Maybe try requests.put instead of requests.post (you want to modify an existing resource, not creating one)

rparent
  • 630
  • 7
  • 14
0

I was having this same problem (using perl), getting a "success" message when trying to change the title/description via imgur API v3 despite no change actually taking place, and finally discovered the problem: I had to manually set the "Content-Type: application/json" header for the request to be processed. Failure to do so returned a 200/success message but made no actual change. The same issue prevented me from uploading images with the new API until corrected.

ccjuju
  • 507
  • 4
  • 15
0

I know it's old question, but maybe it will help someone. For me it works.

Add header:

'Content-Type': 'application/json'

And in requests.post use json instead of data

r = requests.post(url,
     headers={'Authorization':'Bearer '+access_token, 'Content-Type': 'application/json'},
     json={'description':'blahblahblah'}, verify=False)
akn
  • 3,712
  • 26
  • 43