HTTPretty
HTTPretty copied to clipboard
ssl requests do not get passed through correctly
As demonstrated by the shell session below, there is a bug in how ssl is handled when passing through HTTPretty. I didn't see a note in the readme about it having this limitation.
>>> import requests
>>> from httpretty import HTTPretty
>>> url = 'https://www.cloudflare.com/ips'
>>>
>>> response = requests.get(url)
>>> original_content = response.content
>>>
>>> HTTPretty.reset()
>>> HTTPretty.enable()
>>>
>>> response = requests.get(url)
>>> new_content = response.content
>>> print new_content == original_content
False
>>>
>>> HTTPretty.disable()
>>> response = requests.get(url)
>>> newer_content = response.content
>>> print newer_content == original_content
True
>>> print new_content
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
Yeah, I'm having the same problem (version 0.5.9). Using urllib2
, the following raises HTTPError
(if you trap the error and inspect it, you see a response code of 400 and the same message given above):
import urllib2
from httpretty import HTTPretty
url = 'https://www.cloudflare.com/ips'
HTTPretty.reset()
HTTPretty.enable()
response = urllib2.urlopen(url)
(I've been getting the same thing from a couple of other domains, too, so it's not specific to CloudFlare, though that error message seems to be specific to nginx.)
This appears to be due to HTTPretty not implementing a proper SSL wrapper. ssl.wrap_socket
is replaced by fake_wrap_socket
, a no-op, when HTTPretty is enabled. It seems we must mock all HTTPS connections if HTTPretty is enabled, not just those matching our desired URIs.
Has anyone come up with a workaround for this?
I fixed this issue in my fork: https://github.com/pegler/httpretty I also added the ability to pass in a function to register_uri that accepts the data sent, so that it can respond to dynamically to what was sent instead of having to hardcode everything.
It was a long time ago, and I don't really remember making those changes.
+1 Same problem, not sure how this issue is not a major critical bug.
+1 this is fairly recent
Hey, folks, please refrain from +1 or "thumbs up" or "me too" comments. Contrary to what it might appears to you, such comments are not productive and might even lead to the project owners disabling comments for the issue. We don't need this, really.
@kostix sorry but this is def a way to prioritise issue priority and is quite commonly accepted.
I have managed to resolve the issue as there appears to be some conflict in the lib dependencies (as expected)..
deleted the vm and then recreate with unpinned dependencies should all resolve "nicely"
Hey @rosscdh, Do you mind sharing your fix?
Hey Yarden,
Am afk atm but in brief. Reinstall brew OpenSSL and then reinstall all the url requirements urllib3 requests requests[security] off the top of my head..
Will send version numbers later
On Thursday, 24 March 2016, Yarden Sachs [email protected] wrote:
Hey @rosscdh https://github.com/rosscdh, Do you mind sharing your fix?
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/gabrielfalcao/HTTPretty/issues/35#issuecomment-200901329
Any news ?
HTTPretty needs some TLC which I intend to work on ASAP 😬