alexis-mignon / python-flickr-api

A python implementation of the Flickr API
BSD 3-Clause "New" or "Revised" License
367 stars 108 forks source link

Unauthorized Error 401 when I try to set the authorization verifier #46

Closed mhossameldin closed 9 years ago

mhossameldin commented 10 years ago

Hello

I was following the tutorial provided on the git repositery to start working with flickr_api

It was going fine until I wanted to set the verifier for the authorization handler.

I followed the steps and copied the code from the tag, but I got the following error.

Keeping in mind that i am using the latest version of flickr_api

runfile('C:/Users/Mahmoud/Documents/Python Scripts/getImages.py', wdir=r'C:/Users/Mahmoud/Documents/Python Scripts') runfile('C:/Users/Mahmoud/Documents/Python Scripts/getImages.py', wdir=r'C:/Users/Mahmoud/Documents/Python Scripts') https://www.flickr.com/services/oauth/authorize?oauth_token=72157644795843302-08e10638e37118fe&perms=read runfile('C:/Users/Mahmoud/Documents/Python Scripts/getImages.py', wdir=r'C:/Users/Mahmoud/Documents/Python Scripts') https://www.flickr.com/services/oauth/authorize?oauth_token=72157644808317325-3b1847232bd3d89f&perms=read Traceback (most recent call last): File "", line 1, in File "C:\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile execfile(filename, namespace) File "C:/Users/Mahmoud/Documents/Python Scripts/getImages.py", line 15, in a.set_verifier("e1b5dd87477f16b1") File "C:\Anaconda\lib\site-packages\flickr_api\auth.py", line 141, in set_verifier resp = urllib2.urlopen(req.to_url()) File "C:\Anaconda\lib\urllib2.py", line 127, in urlopen return _opener.open(url, data, timeout) File "C:\Anaconda\lib\urllib2.py", line 410, in open response = meth(req, response) File "C:\Anaconda\lib\urllib2.py", line 523, in http_response 'http', request, response, code, msg, hdrs) File "C:\Anaconda\lib\urllib2.py", line 448, in error return self._call_chain(_args) File "C:\Anaconda\lib\urllib2.py", line 382, in _call_chain result = func(_args) File "C:\Anaconda\lib\urllib2.py", line 531, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Unauthorized

alexis-mignon commented 10 years ago

Hello,

Could you please add a sample code that raises the error ?

Regards

Alexis Le 23 mai 2014 14:44, "Mahmoud Aly" notifications@github.com a écrit :

Hello

I was following the tutorial provided on the git repositery to start working with flickr_api

It was going fine until I wanted to set the verifier for the authorization handler.

I followed the steps and copied the code from the tag, but I got the following error.

Keeping in mind that i am using the latest version of flickr_api

runfile('C:/Users/Mahmoud/Documents/Python Scripts/getImages.py', wdir=r'C:/Users/Mahmoud/Documents/Python Scripts') runfile('C:/Users/Mahmoud/Documents/Python Scripts/getImages.py', wdir=r'C:/Users/Mahmoud/Documents/Python Scripts')

https://www.flickr.com/services/oauth/authorize?oauth_token=72157644795843302-08e10638e37118fe&perms=read runfile('C:/Users/Mahmoud/Documents/Python Scripts/getImages.py', wdir=r'C:/Users/Mahmoud/Documents/Python Scripts')

https://www.flickr.com/services/oauth/authorize?oauth_token=72157644808317325-3b1847232bd3d89f&perms=read Traceback (most recent call last): File "", line 1, in File "C:\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile execfile(filename, namespace) File "C:/Users/Mahmoud/Documents/Python Scripts/getImages.py", line 15, in a.set_verifier("e1b5dd87477f16b1") File "C:\Anaconda\lib\site-packages\flickr_api\auth.py", line 141, in set_verifier resp = urllib2.urlopen(req.to_url()) File "C:\Anaconda\lib\urllib2.py", line 127, in urlopen return _opener.open(url, data, timeout) File "C:\Anaconda\lib\urllib2.py", line 410, in open response = meth(req, response) File "C:\Anaconda\lib\urllib2.py", line 523, in http_response 'http', request, response, code, msg, hdrs) File "C:\Anaconda\lib\urllib2.py", line 448, in error return self._call_chain(_args) File "C:\Anaconda\lib\urllib2.py", line 382, in _call_chain result = func(_args) File "C:\Anaconda\lib\urllib2.py", line 531, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Unauthorized

-- Reply to this email directly or view it on GitHubhttps://github.com/alexis-mignon/python-flickr-api/issues/46 .

useEvil commented 10 years ago

I'm getting this error too.

auth = flickr_api.auth.AuthHandler() auth.set_verifier('oauth_verifier')

error: urllib2.HTTPError: HTTP Error 401: Unauthorized

I think you need to update from oauth to oauth2

useEvil commented 10 years ago

The string ‘oauth_verifier’ was just a place holder. I was replacing it with the actual value returned by Flickr. Anyway, I found a different solution.

On Jul 1, 2014, at 4:06 AM, NerdyTex notifications@github.com wrote:

Sorry for the late answer. @useEvil the code that you show above cannot work the 'oauth_verifier' string has to be replaced by the corresponding field returned by Flickr servers. You need to follow the process shown in the wiki.

— Reply to this email directly or view it on GitHub.

lapierdami commented 10 years ago

Hi. I've the same problem. Here the code:

a = flickr_api.auth.AuthHandler() #creates the AuthHandler object verifi='xxxxxxxxxxx' a.set_verifier(verifi)

and here the error Traceback (most recent call last): File "verifier.py", line 15, in a.set_verifier(verifi) File "/home/damiano/flickr/python/python-flickr-api/flickr_api/auth.py", line 153, in set_verifier resp = urllib2.urlopen(req.to_url()) File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.7/urllib2.py", line 410, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 523, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 448, in error return self._call_chain(_args) File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain result = func(_args) File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Unauthorized

alexis-mignon commented 10 years ago

Hello,

I'm sorry (again) for the late answer, i have not been able to reproduce the error. Do you always have the problem ?

Which version do you use ?

Alexis

alexis-mignon commented 9 years ago

Hello,

It seems that the error comes from the fact that the verifier is not used with the object that created the authentication URL.

Please make sure that all the steps are carefully followed within the same session.

Best regards,

Alexis

nigelb commented 8 years ago

Hi,

Just a snippet of code to demonstrate the solution to people who arrive here and are still scratching their heads:

import flickr_api

flickr_api.set_keys(api_key = 'my_api_key', api_secret = 'my_secret') a = flickr_api.auth.AuthHandler() url = a.get_authorization_url("read") print url verifier = raw_input("Verifier code: ")

a.set_verifier(verifier) a.save("flickr_credentials.dat")

  1. Run the code.
  2. Paste the displayed URL into a browser and accept the permission request.
  3. Copy the oauth_verifier field and paste it into the terminal at the "Verifier code: " prompt.

This should result in the creation of the flickr_credentials.dat credential file which can be used like this:

import flickr_api

flickr_api.set_keys(api_key = 'my_api_key', api_secret = 'my_secret') flickr_api.set_auth_handler("flickr_credentials.dat") user = flickr_api.test.login() print user.getPhotosets()

Hope this helps.