tumblr / pytumblr

A Python Tumblr API v2 Client
Apache License 2.0
724 stars 199 forks source link

`ValueError: Only unicode objects are escapable` on client.info() #177

Open mechanical-girl opened 4 months ago

mechanical-girl commented 4 months ago

When calling client.info(), the following error occurs:

Traceback (most recent call last):
  File "/Users/mechanical-girl/blogup/main.py", line 92, in <module>
    register()
  File "/Users/mechanical-girl/blogup/main.py", line 89, in register
    client.info()
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/pytumblr/__init__.py", line 39, in info
    return self.send_api_request("get", "/v2/user/info")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/pytumblr/__init__.py", line 578, in send_api_request
    return self.request.get(url, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/pytumblr/request.py", line 49, in get
    resp = requests.get(url, allow_redirects=False, headers=self.headers, auth=self.oauth)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/requests/sessions.py", line 575, in request
    prep = self.prepare_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/requests/sessions.py", line 484, in prepare_request
    p.prepare(
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/requests/models.py", line 371, in prepare
    self.prepare_auth(auth, url)
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/requests/models.py", line 602, in prepare_auth
    r = auth(self)
        ^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/requests_oauthlib/oauth1_auth.py", line 103, in __call__
    r.url, headers, _ = self.client.sign(
                        ^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 351, in sign
    ('oauth_signature', self.get_oauth_signature(request)))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 165, in get_oauth_signature
    uri, headers, body = self._render(request)
                         ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 247, in _render
    headers = parameters.prepare_headers(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/oauthlib/oauth1/rfc5849/utils.py", line 25, in wrapper
    return target(params, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/oauthlib/oauth1/rfc5849/parameters.py", line 53, in prepare_headers
    escaped_value = utils.escape(value)
                    ^^^^^^^^^^^^^^^^^^^
  File "/Users/mechanical-girl/blogup/lib/python3.12/site-packages/oauthlib/oauth1/rfc5849/utils.py", line 49, in escape
    raise ValueError('Only unicode objects are escapable. ' +
ValueError: Only unicode objects are escapable. Got <generator object to_unicode.<locals>.<genexpr> at 0x103f43760> of type <class 'generator'>.
mechanical-girl commented 4 months ago

This appears to be fixed by adding from __future__ import unicode_literals to the top of the file. Could documentation be updated to reflect that?

Never mind, this is considered bad practice.