sybrenstuvel / flickrapi

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

token_valid. print token_cache.token: error: RecursionError: maximum recursion depth exceeded while calling a Python object #110

Closed oPromessa closed 1 year ago

oPromessa commented 6 years ago

Hey guys. Excellent job on flickrapi.

Since a few days ago I'm getting a really weird result from flickrapi/Flickr on TravisCI testing. I've tried with both flickrapi 2.3.6 and 2.4. It seems to be on a six module function six.text_type. This occurs with python 2.6, 3.6 or 3.7-dev. Again from a few days ago as this code has been running for several months.

six.text_type(self).encode('utf-8')
  [Previous line repeated 194 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object

I have a token saved on the local file/database and I check the permissions (this has been working for months) with the following code.

    def getCachedToken(self):
        """
        Attempts to get the flickr token from disk.
        """
        global nuflickr

        logging.info('Obtaining Cached token')
        logging.debug('TOKEN_CACHE:[{!s}]'.format(TOKEN_CACHE))
        nuflickr = flickrapi.FlickrAPI(FLICKR["api_key"],
                                       FLICKR["secret"],
                                       token_cache_location=TOKEN_CACHE)

        try:
            # Check if token permissions are correct.
            if nuflickr.token_valid(perms='delete'):
                logging.info('Cached token obtained: {!s}'
                             .format(nuflickr.token_cache.token))    # this is line 987 reported on the Traceback below
                return nuflickr.token_cache.token
            else:
                logging.info('Token Non-Existant.')
                return None
        except:
            reportError(Caught=True,
                        CaughtPrefix='+++',
                        CaughtCode='007',
                        CaughtMsg='Unexpected error in token_valid',
                        exceptSysInfo=True)
            raise

and I'm getting

[1966][2018.02.21 19:14:58]:[MainProcess][INFO    ]:[root] Obtaining Cached token
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[root] TOKEN_CACHE:[token]
[1966][2018.02.21 19:14:58]:[MainProcess][INFO    ]:[flickrapi.core] Calling {'method': 'flickr.auth.oauth.checkToken', 'format': 'etree', 'nojsoncallback': 1}
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[flickrapi.core] Wrapping call <bound method FlickrAPI._flickr_call of [FlickrAPI for key "[secure]"]>(self, (), {'timeout': None, 'format': 'rest', 'method': 'flickr.auth.oauth.checkToken', 'nojsoncallback': 1})
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[flickrapi.core] Calling {'format': 'rest', 'method': 'flickr.auth.oauth.checkToken', 'nojsoncallback': 1}
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[requests_oauthlib.oauth1_auth] Signing request <PreparedRequest [POST]> using client <Client client_key=[secure], client_secret=****, resource_owner_key=[secure], resource_owner_secret=****, signature_method=HMAC-SHA1, signature_type=AUTH_HEADER, callback_uri=None, rsa_key=None, verifier=None, realm=None, encoding=utf-8, decoding=utf-8, nonce=None, timestamp=None>
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[requests_oauthlib.oauth1_auth] Including body in call to sign: True
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[oauthlib.oauth1.rfc5849] Collected params: [('oauth_nonce', '26328066831001355581519240498'), ('oauth_timestamp', '1519240498'), ('oauth_version', '1.0'), ('oauth_signature_method', 'HMAC-SHA1'), ('oauth_consumer_key', '[secure]'), ('oauth_token', '[secure]'), ('format', 'rest'), ('method', 'flickr.auth.oauth.checkToken'), ('nojsoncallback', '1')]
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[oauthlib.oauth1.rfc5849] Normalized params: format=rest&method=flickr.auth.oauth.checkToken&nojsoncallback=1&oauth_consumer_key=[secure]&oauth_nonce=26328066831001355581519240498&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1519240498&oauth_token=[secure]&oauth_version=1.0
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[oauthlib.oauth1.rfc5849] Normalized URI: https://api.flickr.com/services/rest/
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[oauthlib.oauth1.rfc5849] Signing: signature base string: POST&https%3A%2F%2Fapi.flickr.com%2Fservices%2Frest%2F&format%3Drest%26method%3Dflickr.auth.oauth.checkToken%26nojsoncallback%3D1%26oauth_consumer_key%3D[secure]%26oauth_nonce%3D26328066831001355581519240498%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1519240498%26oauth_token%3D[secure]%26oauth_version%3D1.0
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[oauthlib.oauth1.rfc5849] Signature: RZ/jDXSg7582uxUTFTQBSvRxAaI=
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[oauthlib.oauth1.rfc5849] Encoding URI, headers and body to utf-8.
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[requests_oauthlib.oauth1_auth] Updated url: https://api.flickr.com/services/rest/
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[requests_oauthlib.oauth1_auth] Updated headers: {b'User-Agent': b'python-requests/2.18.4', b'Accept-Encoding': b'gzip, deflate', b'Accept': b'*/*', b'Connection': b'keep-alive', b'Content-Length': b'64', b'Content-Type': b'application/x-www-form-urlencoded', b'Authorization': b'OAuth oauth_nonce="26328066831001355581519240498", oauth_timestamp="1519240498", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="[secure]", oauth_token="[secure]", oauth_signature="RZ%2FjDXSg7582uxUTFTQBSvRxAaI%3D"'}
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[requests_oauthlib.oauth1_auth] Updated body: b'format=rest&method=flickr.auth.oauth.checkToken&nojsoncallback=1'
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[urllib3.connectionpool] Starting new HTTPS connection (1): api.flickr.com
[1966][2018.02.21 19:14:58]:[MainProcess][DEBUG   ]:[urllib3.connectionpool] https://api.flickr.com:443 "POST /services/rest/ HTTP/1.1" 200 195
[1966][2018.02.21 19:14:58]:[MainProcess][INFO    ]:[flickrapi.core] REST Parser: using xml.etree.cElementTree
[1966][2018.02.21 19:14:58]:[MainProcess][ERROR   ]:[root] +++#007: Unexpected error in token_valid
[1966][2018.02.21 19:14:58]:[MainProcess][ERROR   ]:[root] (<class 'RecursionError'>, RecursionError('maximum recursion depth exceeded while calling a Python object',), <traceback object at 0x7f85275216c8>)
Traceback (most recent call last):
  File "uploadr.py", line 4576, in <module>
    flick = Uploadr()
  File "uploadr.py", line 787, in __init__
    self.token = self.getCachedToken()
  File "uploadr.py", line 987, in getCachedToken
    .format(nuflickr.token_cache.token))
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/flickrapi/auth.py", line 130, in __str__
    return six.text_type(self).encode('utf-8')
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/flickrapi/auth.py", line 130, in __str__
    return six.text_type(self).encode('utf-8')
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/flickrapi/auth.py", line 130, in __str__
    return six.text_type(self).encode('utf-8')
  [Previous line repeated 194 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object

Thanks in advance, oPromessa

sybrenstuvel commented 6 years ago

It seems to be on a six module function six.text_type.

Which version do you have installed?

oPromessa commented 6 years ago

Thanks for your support. (side to self 312.6 and 312.2??)

Seems solved with flickrapi 2.4 with both Python 2.7 and 3.6

It fails with flickrapi 2.3 with Python 3.6

It does occur when I force on TravisCI requirements.txt six version 1.11.0 and flickrapi 2.3 Output for pip install below.

Output of the error.

[1991][2018.02.22 19:38:29]:[MainProcess][DEBUG   ]:[requests_oauthlib.oauth1_auth] Updated headers: {b'User-Agent': b'python-requests/2.18.4', b'Accept-Encoding': b'gzip, deflate', b'Accept': b'*/*', b'Connection': b'keep-alive', b'Content-Length': b'64', b'Content-Type': b'application/x-www-form-urlencoded', b'Authorization': b'OAuth oauth_nonce="63987177007510055201519328309", oauth_timestamp="1519328309", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="[secure]", oauth_token="[secure]", oauth_signature="h8ZClyUroKaf34Pw5ORgE8wohy8%3D"'}
[1991][2018.02.22 19:38:29]:[MainProcess][DEBUG   ]:[requests_oauthlib.oauth1_auth] Updated body: b'format=rest&method=flickr.auth.oauth.checkToken&nojsoncallback=1'
[1991][2018.02.22 19:38:29]:[MainProcess][DEBUG   ]:[urllib3.connectionpool] Starting new HTTPS connection (1): api.flickr.com
[1991][2018.02.22 19:38:29]:[MainProcess][DEBUG   ]:[urllib3.connectionpool] https://api.flickr.com:443 "POST /services/rest/ HTTP/1.1" 200 195
[1991][2018.02.22 19:38:29]:[MainProcess][INFO    ]:[flickrapi.core] REST Parser: using xml.etree.cElementTree
[1991][2018.02.22 19:38:29]:[MainProcess][ERROR   ]:[root] +++#007: Unexpected error in token_valid
[1991][2018.02.22 19:38:29]:[MainProcess][ERROR   ]:[root] (<class 'RecursionError'>, RecursionError('maximum recursion depth exceeded while calling a Python object',), <traceback object at 0x7fd13e82f508>)
Traceback (most recent call last):
  File "uploadr.py", line 4824, in <module>
    flick = Uploadr()
  File "uploadr.py", line 787, in __init__
    self.token = self.getCachedToken()
  File "uploadr.py", line 987, in getCachedToken
    .format(nuflickr.token_cache.token))
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/flickrapi/auth.py", line 130, in __str__
    return six.text_type(self).encode('utf-8')
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/flickrapi/auth.py", line 130, in __str__
    return six.text_type(self).encode('utf-8')
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/flickrapi/auth.py", line 130, in __str__
    return six.text_type(self).encode('utf-8')
  [Previous line repeated 194 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object

Output for pip install below.

$ pip install -r requirements.txt
Requirement already satisfied: six>=1.11.0 in /home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages (from -r requirements.txt (line 1))
Collecting flickrapi==2.3 (from -r requirements.txt (line 13))
  Downloading flickrapi-2.3-py3-none-any.whl
Collecting pytest-flakes (from -r requirements.txt (line 15))
  Downloading pytest_flakes-2.0.0-py2.py3-none-any.whl
Collecting coverage (from -r requirements.txt (line 16))
  Downloading coverage-4.5.1-cp36-cp36m-manylinux1_x86_64.whl (202kB)
Collecting requests-toolbelt>=0.3.1 (from flickrapi==2.3->-r requirements.txt (line 13))
[...]
  Stored in directory: /home/travis/.cache/pip/wheels/6d/22/a3/5b776623c29d057b5a71126cc3d7860ccfb08d5e4c377c3b72
  Running setup.py bdist_wheel for oauthlib: started
  Running setup.py bdist_wheel for oauthlib: finished with status 'done'
  Stored in directory: /home/travis/.cache/pip/wheels/e5/46/f7/bb2fde81726295a13a71e3c6396d362ab408921c6562d6efc0
Successfully built pytest-cache oauthlib
Installing collected packages: chardet, idna, certifi, urllib3, requests, requests-toolbelt, oauthlib, requests-oauthlib, flickrapi, apipkg, execnet, pytest-cache, pyflakes, pytest-flakes, coverage
Successfully installed apipkg-1.4 certifi-2018.1.18 chardet-3.0.4 coverage-4.5.1 execnet-1.5.0 flickrapi-2.3 idna-2.6 oauthlib-2.0.6 pyflakes-1.6.0 pytest-cache-1.0 pytest-flakes-2.0.0 requests-2.18.4 requests-oauthlib-0.8.0 requests-toolbelt-0.8.0 urllib3-1.22