In our project we are reading historical data(past 45 days data) from solr db.We can read maximum 5 days data in single api call so we are calling api sequentially in a for loop for 45 days.But observing some 400 status codes for some api call' in between randomly..like for total 9 api calls some giving 200 and some 400 response codes in between randomly..like if I rerun my job, then api call which gave 400 earlier might give 200 this time.
I checked with API owner, they said it is because you are calling next api call before earlier one is completed.
1.) how to identify if api request is completed in python , so that can call next api only when previous request is completed.This can be answered by API owner or there is any way in python request library
2.) should i think of using sleep statement after each api call.But how to know sleep time and is this efficient way ?
Thanks
Related
I want to get info from API via Python, which has infinite info updating (it is live - for example live video or live monitoring). So I want to stop this GET request after interval (for example 1 second), then process these information and then repeat this cycle.
Any ideas? (now I am using requests module, but I do not know, how to stop receiving data and then get them)
I might be off here, but if you hit an endpoint at a specific time, it should return the JSON at that particular moment. You could then store it and use it in whatever process you have created.
If you want to hit it again, you would just use requests to hit the endpoint.
I have a Flask app which does some external API calls and combines this data.
The external API call can take up to ~40 seconds.
Currently I cache the result using flask_caching with an expiry time of 1 hour.
#app.route('/api/pos')
#cache.cached(timeout=3600)
def get_pos():
return jsonify( [LONG TIME API CALL] )
How do I make flask automatically do the external API call when it's caches expires, as to refresh the cache? Instead of the user having to wait 40 seconds when the cache expired.
I was thinking about a Crob job which calls my flask app every 1 hour with for example cUrl. But there has to be a prettier method.
So to summarize: is there some kind of event which can trigger when flasks cache times out?
Best regards, sorry for my formulation of the question as English is not my native language.
I am making an GET call through requests in Python 3.7. This GET request will trigger a job. Once the job gets triggered on the host side it has set of attributes such as run id and other parameters. The host has an idle timeout of like 120 seconds and the job that was triggered will run more than 120 seconds. Since the get request is blocked until a response is thrown, in this case it times out after 120 seconds we are getting expected 504 error. But if the job completes within 120 seconds, the get request header response has details of run id and other attributes.
What I am trying to accomplish is the moment request.get is submitted, is there a way to get immediate response back with run id and other details. I can use that run id to poll the the host to get back the response code even after 120 seconds through a separate API call. I tried to search the blog but was unsuccessful. If request module cannot help in this case, please advice if other modules will come handy for my need.
Any input is much appreciated.
I am new to this concept.Currently,I am working on API calls.
Background:
Here is my requirement.
I have a get API url
/details/v1/employee/{employeeid}/employeecodes?%s&limit=5000&offset={1}.
This Url gets one record at a time.So,I need to pass employeeid value to this url in a loop.
I have 300K employee in a list.
Issue:
Issue here is ,I have a limit on API calls that is 25K per day. But I have 300K employee,the program errors out saying out of call volume quota.
Question:
Is there any approach that I can limit my API calls?
I'm using the Instagram API to retrieve all photos from a list of hashtags. Starting today, I've been hitting the API rate limits (429 error, specifically). To debug this, I've been trying to see how to get the number of calls I have left per hour and incorporate that into my script.
The Instagram API says that you can access the number of calls left in the hour through the HTTP header, but I'm not sure how to access that in Python.
The following fields are provided in the header of each response and their values are related to the type of call that was made (authenticated or unauthenticated):
X-Ratelimit-Remaining: the remaining number of calls available to your app within the 1-hour window
X-Ratelimit-Limit: the total number of calls allowed within the 1-hour window
http://instagram.com/developer/limits
How would I access this data in Python?
I assumed it was much a much fancier solution based on a few other answers on SO, but after some researching, I found a really simple solution!
import requests
r = requests.get('URL of the API response here')
r.headers