python requests can not send https request - python

I installed requests.
But I can not send https request, even as simple as this:
requests.get('https://www.google.com')
The error message is:
_ssl.c:504: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
UPDATES: I can send https request using other method, urllib2, httplib can send https request sucessfully

This is not a problem with requests, or even with Python.
You are most likely using a proxy server that has not been properly configured to handle SSL connections. The exact problem is very much dependent on the proxy server. A Google search on the 140770FC error will give you many hits and discussions on how to diagnose this.
Note that even if you have not configured a proxy on your local machine, a corporate firewall could still be forcing HTTPS connections to go over a proxy at the network boundaries.

Related

Why am I seeing InvalidProxyConfigurationWarning when using an HTTPS proxy with urllib3?

When using a urllib3.ProxyManager() with an HTTPS proxy URL I'm seeing a warning called InvalidProxyConfigurationWarning on version 1.25.9 of urllib3. I didn't get this warning before, what does it mean?
This warning is new in urllib3 v1.25.9 and means that your proxy which is configured to use HTTPS is not doing what you intended.
See this issue for more information: https://github.com/urllib3/urllib3/issues/1850
Copied below is the text from the issue.
urllib3 up to v1.25.x doesn't support HTTPS proxies. When connecting to an HTTPS URL, urllib3 contacts the proxy via HTTP instead of HTTPS even if your proxy URL specifies HTTPS. In urllib3 v1.26.x we're planning on supporting HTTPS proxies properly and are giving an early warning to users to switch their proxy URLs from HTTPS to HTTP to not encounter issues when upgrading later.
import urllib3
# HTTPS proxy, should change!
http = urllib3.ProxyManager("https://1.2.3.4")
http.request("GET", "https://example.com") # Warning would be raised here.
# Switch to this, will maintain current behavior when connecting to HTTPS URLs.
http = urllib3.ProxyManager("http://1.2.3.4")
http.request("GET", "https://example.com") # Warning won't be raised, same behavior as above.
Your proxy may be configured externally like in a HTTPS_PROXY environment variable or via requests.Session(proxy_url=...) or configured by your OS.
(FYI I'm the current lead maintainer of urllib3)

Using Tor Hidden Services With Python

As you already know in order to use Tor without the Tor Browser you need to have Tor installed on the command line and running afterwards you can configure programs like Curl to use the Tor SOCKS5 proxy on port 9050 I am working on implementing this in Python I have already finished this using subprocess combined with Curl and so far i am using requests combined with a proxy list the only proxy in the list is socks5://127.0.0.1:9050 and this works for clearnet websites i have checked by running the request without the proxy and with the proxy using HTTPBin and they are different IP addresses but i have tried to resolve a .onion domain with this same code but it doesn't resolve with the error Name or service not known. What do I do in order to fix this? And what's the cause
Edit: I read in a previous question that maybe Tor was not running or listening for connections the proxy takes connections for clearnet websites from the same script and redirects to the Tor network but does not resolve .onion websites and i checked to make sure and Tor is indeed running and listening for connections on port 9050 and i have checked the network connection it is indeed active and can ping clearnet websites but the script won't resolve .onion domains
#!/usr/bin/python
import requests
Proxy = {'http' : 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'}
Request_Server = requests.get('https://www.facebookcorewwwi.onion/')

How to disable SNI in Python Requests?

I'm attempting to use requests to access a remote server over SSL. Unfortunately it's misconfigured such that it responds with the error TLSV1_UNRECOGNIZED_NAME during the SNI handshake, which is ignored by browsers but raises an exception in requests.
This appears to be the same issue as this question, but in Python rather than Java: SSL handshake alert: unrecognized_name error since upgrade to Java 1.7.0`
The connection works perfectly in Python 2, which doesn't support SNI. How can I disable SNI in Python 3 so that the connection works?
I couldn't find a way to disable SNI on the requests level, but I found a hack that will trick it into thinking SNI isn't supported. Add this code before importing requests (not after, or it will be too late):
import ssl
ssl.HAS_SNI = False

Installing Chrome Native Client SDK

For the last few days I have been trying ti install the Native Client SDK for chrome in Windows and/or Ubuntu.
I'm behind a corporate network, and the only internet access is through an HTTP proxy with authentication involved.
When I run "naclsdk update" in Ubuntu, it shows
"urlopen error Tunnel connection failed: 407 Proxy Authentication Required"
Can anyone please help ?
Try to download this file:
http://commondatastorage.googleapis.com/nativeclient-mirror/nacl/nacl_sdk/naclsdk_manifest2.json
It is the native client update summary, but in the URL I replaced the https with http. If you view the JSON file, you will see the different pepper_xx versions available. Use the links to download the one you want, but again replace https with http.
The naclsdk update tool is very difficult to use for those of us behind a strict firewall. It would be nice if Google provided a direct link to the latest SDK.
I got a solution-
not a direct one, though.
managed to use a program to redirect the HTTPS traffic through the HTTP proxy.
I used the program called "proxifier". Works great.

How to connect pop3 server via http proxy?

I am using poplib to receive email but my computer accesses internet via http proxy. It seems that poplib does not support proxy? How to use poplib using http proxy? Many thanks!

Categories

Resources