question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request params encoded using system encoding

See original GitHub issue

Perhaps I’m misunderstanding how this is supposed to work, but it looks like all request parameters are encoded using the system locale encoding. (https://github.com/wagnerrp/pytmdb3/blob/master/tmdb3/request.py#L70) This causes problems when the system locale cannot encode all the charaters in the parameters, plus, I have no idea how tmdb is expected to know what encoding you have used to encode the parameters, I suspect it should be using a constant encoding defined by the tmdb api. Portion of a relevant traceback:

File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/api_tmdb.py", line 293, in lookup
    result = _first_result(tmdb3.tmdb_api.searchMovie(title.lower(), adult=True, year=year))
  File "/usr/local/lib/python2.7/dist-packages/tmdb3/tmdb_api.py", line 128, in searchMovie
    return MovieSearchResult(Request('search/movie', **kwargs), locale=locale)
  File "/usr/local/lib/python2.7/dist-packages/tmdb3/request.py", line 71, in __init__
    kwargs[k] = locale.encode(v)
  File "/usr/local/lib/python2.7/dist-packages/tmdb3/locales.py", line 110, in encode
    return dat.encode(self.encoding)
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-13: ordinal not in range(256)

Downstream ticket: http://flexget.com/ticket/2392

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gazpachokingcommented, Feb 6, 2014

Did a bit of testing, looks like tmdb is expecting utf-8 encoding. Did a bit of a hack to get things working again:

# Before. Broken
>>> tmdb3.tmdb_api.searchMovie(u'Generation П')[0]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "build\bdist.win32\egg\tmdb3\tmdb_api.py", line 128, in searchMovie
    return MovieSearchResult(Request('search/movie', **kwargs), locale=locale)
  File "build\bdist.win32\egg\tmdb3\request.py", line 70, in __init__
    kwargs[k] = locale.encode(v)
  File "build\bdist.win32\egg\tmdb3\locales.py", line 110, in encode
    return dat.encode(self.encoding)
  File "C:\Users\chase.sterling\PycharmProjects\Flexget\lib\encodings\cp1252.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u041f' in position 11: character maps to <undefined>

# Hack to fix encoding
>>> tmdb3.locales.set_locale("en", "us", True)
>>> tmdb3.locales.syslocale.encoding = 'utf-8'

# After. Working.
>>> tmdb3.tmdb_api.searchMovie(u'Generation П')[0]
<Movie 'Generation P' (2011)>
0reactions
gregorvolkmanncommented, Oct 2, 2018

tmdb3.locales.syslocale.encoding = 'utf-8' fixed also TMDbError Internal error - Something went wrong. Contact TMDb. on tmdb3.MovieSearch('some string with äüö') Thanks @gazpachoking !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java URL encoding of query string parameters - Stack Overflow
URLEncoder is the way to go. You only need to keep in mind to encode only the individual query string parameter name and/or...
Read more >
Javascript | Encode URL Query Parameter | by Sonika - Medium
My Use case: Need to accept query string parameters in order to make GET requests. When to use encodeURIcomponent() and encodeURI() ? encodeURIComponent...
Read more >
Guide to Java URL Encoding/Decoding - Baeldung
Simply put, URL encoding translates special characters from the URL to a representation that adheres to the spec and can be correctly ...
Read more >
Encoding String Parameters in the URL Request
All string parameters in the URL request must be UTF-8 encoded. String parameters containing non-ASCII characters must be URL-encoded.
Read more >
encodeURIComponent() - JavaScript - MDN Web Docs
The encodeURIComponent() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found