sybrenstuvel / flickrapi

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

OAuth Error Message #133

Open flowv opened 3 years ago

flowv commented 3 years ago

Hello

I try to get my authentification with this code here:

import flickrapi

api_key = u'...'
api_secret = u'...'

flickr = flickrapi.FlickrAPI(api_key, api_secret)
flickr.authenticate_via_browser(perms='read')

For some reason, that i can't understand, the IDE gives me this error message:

127.0.0.1 - - [14/May/2021 08:52:52] code 400, message Bad request version ('¨Y')
127.0.0.1 - - [14/May/2021 08:52:52] "Traceback (most recent call last):
  File "/Users/vincentnowak/Documents/whatever.py", line 10, in <module>
    flickr.authenticate_via_browser(perms='read')
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flickrapi/core.py", line 125, in decorated
    method(self, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flickrapi/core.py", line 609, in authenticate_via_browser
    self.flickr_oauth.auth_via_browser(perms=perms)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flickrapi/auth.py", line 416, in auth_via_browser
    self.verifier = self.auth_http_server.wait_for_oauth_verifier()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flickrapi/auth.py", line 206, in verifier
    assert isinstance(new_verifier, six.text_type), 'verifier must be unicode text type'
AssertionError: verifier must be unicode text type

and the flickr page gives me this error message:

_Oops! Flickr doesn't recognise the "oauth_token" this application is trying to use. An external application has requested your login credentials and permission to perform certain actions on your behalf, but has failed to include all the required data.

You don't really need to know what this means, except that you can't use the application until this problem is fixed. (It's a third-party problem, not a Flickr problem.)

There are lots of applications using the Flickr API. If you are curious about this, visit the Flickr Services page to see more examples of cool stuff. Otherwise, you might like to head to your home page..._

Could you kindly point me into the right direction? That would be great!

dirkroorda commented 3 years ago

I have the same error!

jim-easterbrook commented 3 years ago

Is this related to Flickr changing the oauth callback url from http to https? I don't use FlickrApi's authenticate_via_browser myself, but I've had problems with the local server I use. Flickr introduced the bug over a year ago though, so if this is new it won't be that. :)

randomcascade commented 3 years ago

I'm looking into it. In the meantime I'm curious if you could be experiencing any encoding issues in your project. Maybe due to an IDE or wherever you're getting the authentication info from.

randomcascade commented 3 years ago

Also of interest would be if your code was ported or using parts of Python 2 instead of Python 3. In Python 3 strings should be in Unicode (UTF-8) by default.

randomcascade commented 3 years ago

My plan is to remove the usage of the six library based assert. Then use the Python 3 built-ins or the Unicode library to make sure it's Unicode. I suspect this is just a silly issue with the isinstance and six library.

In general I intend to remove whatever remains of Python 2 compatibility over time.

flowv commented 3 years ago

Also of interest would be if your code was ported or using parts of Python 2 instead of Python 3. In Python 3 strings should be in Unicode (UTF-8) by default.

Thanks a lot! The IDE I am using is the Python 3 IDE on a Mac. I have tried Chome and Safari as browser.

randomcascade commented 3 years ago

Sorry for the delay. In addition to being very busy during the summer months my development machine decided to break on me.

I'm curious are you running this as part of a subprocess or using an IDE button or toolchain to run?

You might try setting PYTHONIOENCODING=utf-8 in whichever locale it's running. Either using export or a setting in your IDE.

mlino commented 3 years ago

@randomcascade, SInce I'm using UTF-8, I did the following:

Edited .profile and added the lines below:

PYTHONIOENCODING=utf-8
export PYTHONIOENCODING

Then, echo $PYTHONIOENCODING
utf-8

Then, I reran the same script and got the same error:

 python3 auth.py
Traceback (most recent call last):
  File "auth.py", line 18, in <module>
    flickr.upload(**params)
  File "/var/packages/py3k/target/usr/local/lib/python3.8/site-packages/flickrapi/core.py", line 494, in upload
    return self._upload_to_form(self.UPLOAD_URL, filename, fileobj, timeout=timeout, **kwargs)
  File "/var/packages/py3k/target/usr/local/lib/python3.8/site-packages/flickrapi/core.py", line 533, in _upload_to_form
    raise IllegalArgumentException("Authentication is required")
flickrapi.exceptions.IllegalArgumentException: Authentication is required