Hi I am trying to use the simpletmdb python wrapper for 'The Movie Database' API and I can't get passed this problem.
When I try to create the objects and call the method for getting movie info I keep getting this error.
in info
response = TMDB._request('GET', path, params)
TypeError: unbound method _request() must be called with TMDB instance as first argument (got str instance instead)
My code for calling it is:
from tmdbsimple import TMDB
tmdb = TMDB('API_KEY')
movie = tmdb.Movies(603)
response = movie.info()
print movie.title
And the neccessary parts of the simpletmdb wrapper are, the Movies class is a subclass of TMDB:
class TMDB:
def __init__(self, api_key, version=3):
TMDB.api_key = str(api_key)
TMDB.url = 'https://api.themoviedb.org' + '/' + str(version)
def _request(method, path, params={}, json_body={}):
url = TMDB.url + '/' + path + '?api_key=' + TMDB.api_key
if method == 'GET':
headers = {'Accept': 'application/json'}
content = requests.get(url, params=params, headers=headers).content
elif method == 'POST':
for key in params.keys():
url += '&' + key + '=' + params[key]
headers = {'Content-Type': 'application/json', \
'Accept': 'application/json'}
content = requests.post(url, data=json.dumps(json_body), \
headers=headers).content
elif method == 'DELETE':
for key in params.keys():
url += '&' + key + '=' + params[key]
headers = {'Content-Type': 'application/json', \
'Accept': 'application/json'}
content = requests.delete(url, data=json.dumps(json_body), \
headers=headers).content
else:
raise Exception('method: ' + method + ' not supported.')
response = json.loads(content.decode('utf-8'))
return response
#
# Set attributes to dictionary values.
# - e.g.
# >>> tmdb = TMDB()
# >>> movie = tmdb.Movie(103332)
# >>> response = movie.info()
# >>> movie.title # instead of response['title']
class Movies:
""" """
def __init__(self, id=0):
self.id = id
# optional parameters: language
def info(self, params={}):
path = 'movie' + '/' + str(self.id)
response = TMDB._request('GET', path, params)
TMDB._set_attrs_to_values(self, response)
return response
The Wrapper can be found on here https://github.com/celiao/tmdbsimple I am just trying to follow the example found there.
Any help would be great!