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

ssl requests do not get passed through correctly #35

Open
pegler opened this issue Feb 20, 2013 · 12 comments
Open

ssl requests do not get passed through correctly #35

pegler opened this issue Feb 20, 2013 · 12 comments

Comments

@pegler
Copy link

pegler commented Feb 20, 2013

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>

@mjjohnson
Copy link

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.)

@jefftrull
Copy link

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.

@rouge8
Copy link

rouge8 commented Feb 3, 2016

Has anyone come up with a workaround for this?

@pegler
Copy link
Author

pegler commented Feb 3, 2016

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.

@yardensachs
Copy link

+1
Same problem, not sure how this issue is not a major critical bug.

@rosscdh
Copy link

rosscdh commented Mar 24, 2016

+1 this is fairly recent

@kostix
Copy link

kostix commented Mar 24, 2016

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.

@rosscdh
Copy link

rosscdh commented Mar 24, 2016

@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"

@yardensachs
Copy link

Hey @rosscdh,
Do you mind sharing your fix?

@rosscdh
Copy link

rosscdh commented Mar 24, 2016

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 notifications@github.com 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
#35 (comment)

@ZuluPro
Copy link

ZuluPro commented Jul 31, 2017

Any news ?

@gabrielfalcao
Copy link
Owner

HTTPretty needs some TLC which I intend to work on ASAP 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants