Comments (6)
Hey @3lixy, would you mind sharing some code snippets showing usage? Thanks!
from tmdbsimple.
I use this when i need rate limiting. It seems to work quite nicely:
https://gist.github.com/gregburek/1441055#gistcomment-2369461
from tmdbsimple.
I currently use https://gist.github.com/gregburek/1441055 comment by oPromessa on Mar4
An example use (not tested):
import tmdbsimple as tmdb
tmdb.API_KEY = 'YOUR_API_KEY_HERE'
# allow access to rate_limited function from the above link (e.g. put it in the same python file you will use it or import it)
# Only allow this function be run once a second
@rate_limited(1)
def rate_limit_call(tmdb_object, function, *args, **kwargs):
return getattr(tmdb_object, function)(*args, **kwargs)
if __name__ == "__main__":
movie_id_list = [100,101,102,103]
for movie_id in movie_list:
# I don't think the movies __init__ actually does a http call so no rate limit needed
movie = tmdb.Movies(movie_id)
# The rate limit of movie.info()
response = rate_limit_call(movie, 'info')
# The rate limit of movie.releases()
response = rate_limit_call(movie, 'releases')
from tmdbsimple.
Is there a way to manage Rate limit properly ?
https://developers.themoviedb.org/3/getting-started/request-rate-limiting
python
I need to fix https://github.com/celiao/tmdbsimple/blob/master/tmdbsimple/base.py#L23 to extends request headers and propose a Pull request, is it ok for you ?
If you want to change the request headers you should be able to do something like (should only need to be done once each run time assuming it does not need to be changed during runtime):
import tmdbsimple as tmdb
tmdb.base.TMDB.headers['HEADER'] = 'HeaderValue'
or
import tmdbsimple as tmdb
tmdb.base.TMDB.headers = {'Content-Type': 'application/json', 'Accept': 'application/json', 'Connection': 'close'}
from tmdbsimple.
I was tinkering around with this in SickRage/SickBeard/Medusa and I found a very simple solution.
If the response code is 429, then sleep for the number of seconds specified in the "Retry-After" header value. This way your normal requests will never be throttled and it lets the TMDB API do all the work of telling you how long you have to wait for your next request.
diff --git a/lib/tmdbsimple/base.py b/lib/tmdbsimple/base.py
index d178f66b3..8c96ccfe1 100644
--- a/lib/tmdbsimple/base.py
+++ b/lib/tmdbsimple/base.py
@@ -13,6 +13,7 @@ Created by Celia Oakley on 2013-10-31.
import json
import requests
+import time
class APIKeyError(Exception):
@@ -72,10 +73,16 @@ class TMDB(object):
url = self._get_complete_url(path)
params = self._get_params(params)
- response = requests.request(
- method, url, params=params,
- data=json.dumps(payload) if payload else payload,
- headers=self.headers)
+ retry = True
+ while retry:
+ retry = False
+ response = requests.request(
+ method, url, params=params,
+ data=json.dumps(payload) if payload else payload,
+ headers=self.headers)
+ if response.status_code == 429:
+ retry = True
+ time.sleep(int(response.headers['Retry-After']))
response.raise_for_status()
response.encoding = 'utf-8'
from tmdbsimple.
Great news! Rate limiting of The Movie Database API has been disabled as of December 16, 2019.
Closing this issue.
from tmdbsimple.
Related Issues (20)
- How to iterate over pages using tmdb.Movies("*") HOT 1
- keywords method in Movies have no kwargs HOT 1
- SSL issues recently? HOT 3
- Can't find "Watch" endpoint HOT 4
- HTTP requests concurrency problems v2.7.0 HOT 12
- Movies, People, Tv HOT 4
- Discover movies
- List of genres HOT 5
- Connection Error while calling Function HOT 1
- Movies credits incorrect request HOT 2
- No module named 'tmdbsimple' HOT 2
- poster_path is None even tho a poster exists HOT 2
- Feature request: Add support for watch providers
- Empty lists HOT 1
- Getting ssl errors recently HOT 1
- Dirty json response from tmdb
- 'Account' object has no attribute 'id' HOT 2
- Change language HOT 2
- Support for contributions to TMDB? HOT 1
- TV watch_providers does not return response HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tmdbsimple.