Create url without request

I am currently using the python request package for JSON requests. Unfortunately, the service I need for the request has a daily maximum request limit. I know correctly, I cache the executed query requests, so if I go beyond this limit, I know where to continue the next day.

r = requests.get('http://someurl.com', params=request_parameters) log.append(r.url) 

However, to use this log the next day, I need to create the request URLs in my program before executing the queries so that I can match them with the lines in the log. Otherwise, it will lower my daily limit. Do any of you have an idea how to do this? I did not find a suitable method in the query package.

+7
python api urlencode python-requests
source share
1 answer

You can use PreparedRequests.

To create a URL, you can create your own request object and prepare it:

 from requests import Session, Request s = Session() p = Request('GET', 'http://someurl.com', params=request_parameters).prepare() log.append(p.url) 

Later, when you are ready to send, you can simply do this:

 r = s.send(p) 

The relevant section of the documentation is here .

+9
source share

All Articles