Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

23 - Add "requests" support #23

Open
mmulich opened this issue Dec 22, 2011 · 0 comments
Open

23 - Add "requests" support #23

mmulich opened this issue Dec 22, 2011 · 0 comments

Comments

@mmulich
Copy link
Owner

mmulich commented Dec 22, 2011

Requests uses a bundled urllib3, here's what I had to do to make wsgi_intercept work with it:

I propose that we add this in a requests_intercept module (with cleaned up imports ;) )

def install_opener():
    # httplib patch
    from wsgi_intercept.httplib_intercept import install
    install()

```
# requests' patch
import wsgi_intercept
from requests.packages.urllib3 import connectionpool

connectionpool.old_http = connectionpool.HTTPConnection
connectionpool.HTTPConnection = wsgi_intercept.WSGI_HTTPConnection

connectionpool.old_https = connectionpool.HTTPSConnection
connectionpool.HTTPSConnection = wsgi_intercept.WSGI_HTTPSConnection

# we need settimeout()
wsgi_intercept.wsgi_fake_socket.settimeout = lambda self, timeout: None
```

def uninstall_opener():
    # httplib unpatch
    from wsgi_intercept.httplib_intercept import uninstall
    uninstall()

```
# requests' unpatch
import wsgi_intercept
from requests.packages.urllib3 import connectionpool

connectionpool.HTTPConnection = connectionpool.old_http
connectionpool.HTTPSConnection = connectionpool.old_https
```


Original link: http://code.google.com/p/wsgi-intercept/issues/detail?id=23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant