TypeError: quote_from_bytes() expected bytes

487 views
Skip to first unread message

Kyle Jorgensen

unread,
Apr 11, 2020, 9:48:40 PM4/11/20
to imdbpy-users
# names = files_df['File Name'].tolist()
names =['Attack Of The Clones',
 'Batman Begins']
found_names = []
for names in range(len(names)):
    ia.search_movie(names)
# files_df['IMdb'] = found_names
found_names

Ultimately I would like to get this into the DataFrame files_df


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-331659a323fd> in <module>
      4 found_names = []
      5 for names in range(len(names)):
----> 6     ia.search_movie(names)
      7 # files_df['IMdb'] = found_names
      8 found_names

~\anaconda3\lib\site-packages\imdb\__init__.py in search_movie(self, title, results, _episodes)
    423             results = 20
    424         if not _episodes:
--> 425             res = self._search_movie(title, results)
    426         else:
    427             res = self._search_episode(title, results)

~\anaconda3\lib\site-packages\imdb\parser\http\__init__.py in _search_movie(self, title, results)
    403 
    404     def _search_movie(self, title, results):
--> 405         cont = self._get_search_content('tt', title, results)
    406         return self.smProxy.search_movie_parser.parse(cont, results=results)['data']
    407 

~\anaconda3\lib\site-packages\imdb\parser\http\__init__.py in _get_search_content(self, kind, ton, results)
    388             params = 'q=%s&s=%s' % (quote_plus(ton.encode('utf8'), safe=''.encode('utf8')), kind.encode('utf8'))
    389         else:
--> 390             params = 'q=%s&s=%s' % (quote_plus(ton, safe=''), kind)
    391         if kind == 'ep':
    392             params = params.replace('s=ep&', 's=tt&ttype=ep&', 1)

~\anaconda3\lib\urllib\parse.py in quote_plus(string, safe, encoding, errors)
    828     else:
    829         space = b' '
--> 830     string = quote(string, safe + space, encoding, errors)
    831     return string.replace(' ', '+')
    832 

~\anaconda3\lib\urllib\parse.py in quote(string, safe, encoding, errors)
    812         if errors is not None:
    813             raise TypeError("quote() doesn't support 'errors' for bytes")
--> 814     return quote_from_bytes(string, safe)
    815 
    816 def quote_plus(string, safe='', encoding=None, errors=None):

~\anaconda3\lib\urllib\parse.py in quote_from_bytes(bs, safe)
    837     """
    838     if not isinstance(bs, (bytes, bytearray)):
--> 839         raise TypeError("quote_from_bytes() expected bytes")
    840     if not bs:
    841         return ''

TypeError: quote_from_bytes() expected bytes

Davide Alberani

unread,
Apr 25, 2020, 11:05:15 AM4/25/20
to imdbpy...@googlegroups.com, ky...@strawhutmedia.com
Hi,
pardon the long delay.

There's an error in the code.
In the for cycle, you are iterating over the indexes of the array
"names" assigning at each
iteration the index value to "names" itself.

You can get what you want with something like:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import imdb

ia = imdb.IMDb()
titles = ['Attack Of The Clones', 'Batman Begins']
found_titles = []
for title in titles:
results = ia.search_movie(title)
found_titles.extend(results)

print(found_titles)


Hope this helps.
> --
> You received this message because you are subscribed to the Google Groups "imdbpy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to imdbpy-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/imdbpy-users/cb9b9a52-caa0-44d2-98e8-b2ce0c3d315d%40googlegroups.com.



--
Davide Alberani <davide....@gmail.com> [PGP KeyID: 0x3845A3D4AC9B61AD]
http://www.mimante.net/
Reply all
Reply to author
Forward
0 new messages