sybrenstuvel / flickrapi

Python Flickr API implementation
https://stuvel.eu/flickrapi
Other
155 stars 33 forks source link

Code 401 signature_invalid during authentication #147

Open sergio-ns opened 7 months ago

sergio-ns commented 7 months ago

As I was getting errors while running my python photo-uploader after not using if for a few weeks, I went on to request a new api key/secret pair which I'm now trying to authenticate, but the authentication fails while calling: flickr.get_request_token(oauth_callback='oob')

with error:

do_request: Status code 401 received, content:
    oauth_problem=signature_invalid
    debug_sbs=POST
    https://www.flickr.com/services/oauth/request_token
 oauth_callback=oob&oauth_consumer_key=<MY_API_KEY>&oauth_nonce=<NONCE>8&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1706650918&oauth_version=1.0
Traceback (most recent call last):
  File "D:\python-flickr\auth.py", line 8, in <module>
    flickr.get_request_token(oauth_callback='oob')
  File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flickrapi\core.py", line 641, in get_request_token
    self.flickr_oauth.get_request_token(oauth_callback=oauth_callback)
  File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flickrapi\auth.py", line 367, in get_request_token
    token_data = self.do_request(self.REQUEST_TOKEN_URL, params)
  File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flickrapi\auth.py", line 262, in do_request
    raise exceptions.FlickrError('do_request: Status code %s received' % req.status_code)
flickrapi.exceptions.FlickrError: do_request: Status code 401 received

here's the authentication script's code:

import flickrapi
import webbrowser
api_key  =
api_secret =  
flickr = flickrapi.FlickrAPI(api_key, api_secret, format='parsed-json')
flickr.get_request_token(oauth_callback='oob')
authorize_url = flickr.auth_url(perms='delete')
webbrowser.open_new_tab(authorize_url)
verifier = str(input('Verifier code: '))
flickr.get_access_token(verifier)

I'm on python 3.10.11 on Windows.

Something must have changed in the whole process and I have probably missed a memo Any clue? Thanks

dfluff commented 6 months ago

@sergio-ns I just ran in to the same problem. I got this error with my newly created FlickrAPI key but it worked fine with the keys in the test scripts in this repo, and with an API key I had generated ~15 years ago leading me to decide the problem was with the API keys not the library. To fix it, I had to go to my App's page in the Flickr App Garden, under "Admin" select "Edit the authentication flow", set the App Type from Web Application to Desktop Application and save the changes. Once done I was able to use this library to do the flickr.get_request_token(aoth_callback='oob') and complete the authorisation sequence without errors.