Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create url without request execution

I am currently using the python requests package to make JSON requests. Unfortunately, the service which I need to query has a daily maximum request limit. Right know, I cache the executed request urls, so in case I come 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, for using this log the the next day I need to create the request urls in my program before actually doing the requests so I can match them against the strings in the log. Otherwise, it would decrease my daily limit. Does anybody of you have an idea how to do this? I didn't find any appropriate method in the request package.

like image 919
Andy Avatar asked Sep 18 '13 09:09

Andy


1 Answers

You can use PreparedRequests.

To build the URL, you can build 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're ready to send, you can just do this:

r = s.send(p) 

The relevant section of the documentation is here.

like image 165
Lukasa Avatar answered Sep 22 '22 10:09

Lukasa