Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

His requests module is an improvement, but he says being able to specify the outbound IP of an HTTP request is out of the scope of his module???

https://github.com/kennethreitz/requests/issues/394

That's why I am still using urllib2.



I'm not sure why you feel this niche requirement requires three question marks. The point of modules like this is to make it easier to do the tasks that 95% of developers are likely to need to do regularly, at the cost of not covering all rare use cases.


It's a reasonable tradeoff for a specific library. But if he's trying to claim that the entire eco-system should put the API above all, then it's worth asking how the 5% use case integrates with this worldview. If I suddenly find I need multiple IPs, do I now need to switch my http client library?


No, you need to do what anyone who has fringe requirements has to do: patch the library yourself. Modify urllib3's (requests uses this as a go between for httplib/http.client) to accept/pass on the source_address that the HTTPConnection from httplib allows and then modify requests to accept/pass this on. This will take, at first glance, maybe half a day with some tests (likely much faster, but I'll allow that there might be something more involved than modifying urllib3's HttpConnectionPool and the accompanying changes for requests's Request model.


The slides don't mention this, but he did touch on having layered designs so the 5% remains possible. However, the primarily exposed api shouldn't get sacrificed for said features. By conceding on a feature that makes the API less usable, you sacrifice more than not having it in the first place (confusion, complexity). Even the GH Issue linked shows a possible solution to the issue using urllib2, which is just a layer down.


I don't understand, what is not usable about being about do to this:

requests.get('news.ycombinator.com', sourceip='1.2.3.4')


I think it is a fairly common requirement to use multiple IPs to avoid throttling or for APIs that restrict access to individual IPs.

The fact that he was confused by it does not help his credibility when he is trying to tell people how to design their libraries.


I have yet to ever have to use multiple outbound IPs from the same machine for an HTTP request from Python. It might be "fairly common" for whatever you do, but in terms of the general population, it's not.


Still, it's a fair point that it at least should be possible. It's fine by me if the uncommon 5% tasks are just as difficult to do in requests or even a little more so, so long as the most common 95% of tasks are a breeze.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: