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

Wrong results using proxies and HTTPS #1359

Closed
astratto opened this issue May 15, 2013 · 6 comments
Closed

Wrong results using proxies and HTTPS #1359

astratto opened this issue May 15, 2013 · 6 comments

Comments

@astratto
Copy link

Hi!

I've found that requests behaves quite weirdly when using a proxy with HTTPS endpoints.
It doesn't change if the proxy is specified using environment variables or using the proxies attribute.

Without proxy

import requests
rs = requests.session()
res = rs.request("get", 
   "https://api.bitbucket.org/1.0/repositories/tutorials/tutorials.bitbucket.org")

print res.text
>> u'{\n    "scm": "hg",
...
"/1.0/repositories/tutorials/tutorials.bitbucket.org"\n}'

Using a proxy

import requests
rs = requests.session()

proxies = { 'https': "http://localhost:3128" }
res = rs.request("get", 
   "https://api.bitbucket.org/1.0/repositories/tutorials/tutorials.bitbucket.org",
    proxies=proxies)

print res.text
>> u'<HTML></HTML>\r\n'

Note 1: that proxy uses a CNTML authentication
Note 2: it works with HTTP endpoints

@Lukasa
Copy link
Member

Lukasa commented May 15, 2013

Requests' current implementation of proxying is lacking when it comes to HTTPS, and right now there isn't a lot we can do about it. We're waiting on urllib3/urllib3#170 (which was urllib3/urllib3#139, which was intended to resolve urllib3/urllib3#50, just in case you wanted to know how long this has been going on) to implement the HTTP CONNECT verb in urllib3.

At the moment, if you try to proxy an HTTPS connection through an HTTP proxy, everything is just...weird. I've seen a wide variety of behaviour. In the best case, the proxy will see that you requested an HTTPS connection and will create such a connection between itself and the endpoint, then strip the SSL and send the data to you over HTTP, but realistically that rarely happens.

Thanks for reporting this bug, and I'm sorry there isn't more we can do right now. You're one of a fairly long list of people who is waiting on this, and I promise that it is very, very high up our list of priorities.

@schlamar
Copy link
Contributor

@astratto Can you try: urllib3/urllib3#170 (comment)

@astratto
Copy link
Author

@schlamar I've just tried and it works! Great!

import sys
sys.path.insert(0, 'requests-new-urllib3-api/requests/packages/')
sys.path.insert(0, 'requests-new-urllib3-api')

import requests
rs = requests.session()

proxies = { 'https': "http://localhost:3128" }
res = rs.request("get",
...    "https://api.bitbucket.org/1.0/repositories/tutorials/tutorials.bitbucket.org",
...     proxies=proxies)

print res.text
{"scm": "hg", "has_wiki": true, "last_updated": "2013-07-19 08:30:48", "creator": null, "forks_count": 3036, "created_on": "2011-12-20 17:35:06", "owner": "tutorials", "logo": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2012/Nov/28/tutorials.bitbucket.org-logo-1456883302-9_avatar.png", "email_mailinglist": "\ndocs@bitbucket.org", "is_mq": false, "size": 50212734, "read_only": false, "fork_of": null, "mq_of": null, "followers_count": 14, "state": "available", "utc_created_on": "2011-12-20 16:35:06+00:00", "website": "", "description": "Site for tutorial101 files", "has_issues": true, "is_fork": false, "slug": "tutorials.bitbucket.org", "is_private": false, "name": "tutorials.bitbucket.org", "language": "html/css", "utc_last_updated": "2013-07-19 06:30:48+00:00", "email_writers": true, "no_public_forks": false, "resource_uri": "/1.0/repositories/tutorials/tutorials.bitbucket.org"}

@JakeAustwick
Copy link

The above seems to get rid of the following error:
requests.exceptions.HTTPError: 501 Server Error: Not Implemented

however it seems as though auth still doesn't work when requesting a https page. I'm now getting:
requests.packages.urllib3.exceptions.ProxyError: Cannot connect to proxy. Socket error: Tunnel connection failed: 407 Proxy Authentication Required.

Any insight?

@Lukasa
Copy link
Member

Lukasa commented Aug 13, 2013

How are you authorising?

@Lukasa
Copy link
Member

Lukasa commented Aug 13, 2013

Ignore that, I've spotted the problem. Yeah, with that set of code you won't get the Proxy-Authorization header. I'll mention it over at our PR.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants