403 error while getting data from Imgur api. Where am I going wrong?

北慕城南 提交于 2019-12-08 05:40:27

问题


From the imgur api page:

For public read-only and anonymous resources, such as getting image info, looking up user comments, creating an anonymous album, etc. all you need to do is send an authorization header with your client_id along with your requests. This also works if you'd like to upload images anonymously (without the image being tied to an account). This lets us know which application is accessing the API.

This is my request using python-requests:

 payload = {"Client-ID":"my client id"}
 r=requests.get("https://api.imgur.com/3/account/imgur/images/0.json?perPage=42&page=6", data = payload,headers={"content-type":"text"},verify=False)

I'm getting a 403 error. All I want to do is retrieve images. Nothing to do with user information, so no need of Oauth2. Where am I going wrong?


回答1:


It looks like you're sending your Client-ID as your request body. The documentation says it needs to be in the Authorization header.

headers = {"Content-Type": "text", "Authorization": "Client-ID YOUR_CLIENT_ID"}
r = requests.get("https://...", headers=headers, verify=False)


来源:https://stackoverflow.com/questions/13918823/403-error-while-getting-data-from-imgur-api-where-am-i-going-wrong

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!