I am sitting behind proxy server.
Proxy is implemented using the PAC File.
I want to install packages using pip but cannot install due to proxy.
Below is the error from my pip.log
> Exception information: Traceback (most recent call last): File
> "C:\Anaconda\lib\site-packages\pip\basecommand.py", line 134, in main
> status = self.run(options, args) File "C:\Anaconda\lib\site-packages\pip\commands\install.py", line 236, in
> run
> requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle) File
> "C:\Anaconda\lib\site-packages\pip\req.py", line 1085, in
> prepare_files
> url = finder.find_requirement(req_to_install, upgrade=self.upgrade) File
> "C:\Anaconda\lib\site-packages\pip\index.py", line 201, in
> find_requirement
> page = self._get_page(main_index_url, req) File "C:\Anaconda\lib\site-packages\pip\index.py", line 554, in _get_page
> return HTMLPage.get_page(link, req, cache=self.cache) File "C:\Anaconda\lib\site-packages\pip\index.py", line 671, in get_page
> resp = urlopen(url) File "C:\Anaconda\lib\site-packages\pip\download.py", line 176, in __call__
> response = self.get_opener(scheme=scheme).open(url) File "C:\Anaconda\lib\urllib2.py", line 404, in open
> response = self._open(req, data) File "C:\Anaconda\lib\urllib2.py", line 422, in _open
> '_open', req) File "C:\Anaconda\lib\urllib2.py", line 382, in _call_chain
> result = func(*args) File "C:\Anaconda\lib\site-packages\pip\download.py", line 155, in
> https_open
> return self.do_open(self.specialized_conn_class, req) File "C:\Anaconda\lib\urllib2.py", line 1181, in do_open
> h.request(req.get_method(), req.get_selector(), req.data, headers) File "C:\Anaconda\lib\httplib.py", line 973, in request
> self._send_request(method, url, body, headers) File "C:\Anaconda\lib\httplib.py", line 1007, in _send_request
> self.endheaders(body) File "C:\Anaconda\lib\httplib.py", line 969, in endheaders
> self._send_output(message_body) File "C:\Anaconda\lib\httplib.py", line 829, in _send_output
> self.send(msg) File "C:\Anaconda\lib\httplib.py", line 791, in send
> self.connect() File "C:\Anaconda\lib\site-packages\pip\download.py", line 122, in connect
> sock = socket.create_connection((self.host, self.port), **self.connection_kwargs) File "C:\Anaconda\lib\socket.py", line 562, in create_connection
> sock.connect(sa) KeyboardInterrupt
Download your PAC proxy file
You can easily figure out which is the right proxy for you
Add it to your .condarc file as follows
proxy_servers:
http: http://ip-address:port
https: http://ip-address:port
Related
I am trying to read an excel table that can be accessed through an url, and load it into a DataFrame.
I'm using pd.read_excel like so:
url = "https://www.recope.go.cr/wp-content/uploads/2020/09/PRECIOS-HIST%C3%93RICOS-CONSUMIDOR-FINAL-1-2.xls"
df = pd.read_excel(url,header=[2,3,4],nrows=347)
and I get :
Traceback (most recent call last):
File "/usr/local/lib/python3.7/urllib/request.py", line 1350, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/usr/local/lib/python3.7/http/client.py", line 1277, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1323, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1272, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1032, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 972, in send
self.connect()
File "/usr/local/lib/python3.7/http/client.py", line 1447, in connect
server_hostname=server_hostname)
File "/usr/local/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/usr/local/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/usr/local/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:1091)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/pandas/util/_decorators.py", line 299, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 336, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "/usr/local/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 1063, in __init__
path=str(self._io), storage_options=storage_options
File "/usr/local/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 939, in inspect_excel_format
content_or_path, "rb", storage_options=storage_options, is_text=False
File "/usr/local/lib/python3.7/site-packages/pandas/io/common.py", line 563, in get_handle
storage_options=storage_options,
File "/usr/local/lib/python3.7/site-packages/pandas/io/common.py", line 288, in _get_filepath_or_buffer
req = urlopen(filepath_or_buffer)
File "/usr/local/lib/python3.7/site-packages/pandas/io/common.py", line 194, in urlopen
return urllib.request.urlopen(*args, **kwargs)
File "/usr/local/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/local/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/usr/local/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.7/urllib/request.py", line 1393, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/usr/local/lib/python3.7/urllib/request.py", line 1352, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:1091)>
I saw something similar in this question but I tried to include the answer code in mine to no avail. I'm a bit new to this but as I couldn't find a solution I thought best to ask here. Is there any way to get around this ssl error?
I tried the solution from the link again and it worked, but I had to change some of the code to:
req = requests.get(url)
df = pd.read_excel(req.content,header=[2,3,4],nrows=347)
For some reason, adding requests made the solution work.
today I'm try to use yahoo-finance library than some issue occur by code.
i provide code and occurred error.
here is library link https://pypi.org/project/yahoo-finance/
code:-
from yahoo_finance import Share
yahoo = Share('YHOO')
print(yahoo.get_open())
Error is
Traceback (most recent call last):
File "/usr/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/usr/lib/python3.6/http/client.py", line 1254, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1300, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1249, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1036, in _send_output
self.send(msg)
File "/usr/lib/python3.6/http/client.py", line 974, in send
self.connect()
File "/usr/lib/python3.6/http/client.py", line 1407, in connect
super().connect()
File "/usr/lib/python3.6/http/client.py", line 946, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/lib/python3.6/socket.py", line 704, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 3, in <module>
yahoo = Share('YHOO')
File "/home/yogesh/.local/lib/python3.6/site-packages/yahoo_finance/__init__.py", line 178, in __init__
self.refresh()
File "/home/yogesh/.local/lib/python3.6/site-packages/yahoo_finance/__init__.py", line 142, in refresh
self.data_set = self._fetch()
File "/home/yogesh/.local/lib/python3.6/site-packages/yahoo_finance/__init__.py", line 181, in _fetch
data = super(Share, self)._fetch()
File "/home/yogesh/.local/lib/python3.6/site-packages/yahoo_finance/__init__.py", line 134, in _fetch
data = self._request(query)
File "/home/yogesh/.local/lib/python3.6/site-packages/yahoo_finance/__init__.py", line 118, in _request
response = yql.YQLQuery().execute(query)
File "/home/yogesh/.local/lib/python3.6/site-packages/yahoo_finance/yql.py", line 61, in execute
'env': DATATABLES_URL
File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/usr/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/usr/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/usr/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>
i have a no idea about this error, please help me to solve this problem. Thank you....
The package is broken. See for example, this issue on GitHub: https://github.com/lukaszbanasiak/yahoo-finance/issues/148
Your best bet would be to indicate on GitHub that the package is not working and perhaps the author is able to help you further.
I recently installed ubuntu 17.04 and when I tried to add a ppa, it gave this traceback stating some unicode error("label empty or too long") relating to idna.py, if it helps my internet runs on proxy
I entered the following command:
sudo -E apt-add-repository ppa:numix/ppa
and recieved following error:
Traceback (most recent call last):
File "/usr/lib/python3.5/encodings/idna.py", line 165, in encode
raise UnicodeError("label empty or too long")
UnicodeError: label empty or too long
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 358, in get_ppa_info
ret = get_ppa_info_from_lp(user, ppa)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 94, in get_ppa_info_from_lp
return get_info_from_lp(lp_url)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 88, in get_info_from_lp
return _get_https_content_py3(lp_url)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 112, in _get_https_content_py3
lp_page = urllib.request.urlopen(request, cafile=LAUNCHPAD_PPA_CERT)
File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.5/urllib/request.py", line 466, in open
response = self._open(req, data)
File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
'_open', req)
File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/usr/lib/python3.5/urllib/request.py", line 1297, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "/usr/lib/python3.5/http/client.py", line 1107, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
self.send(msg)
File "/usr/lib/python3.5/http/client.py", line 877, in send
self.connect()
File "/usr/lib/python3.5/http/client.py", line 1253, in connect
super().connect()
File "/usr/lib/python3.5/http/client.py", line 849, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/lib/python3.5/socket.py", line 694, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.5/socket.py", line 733, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.5/encodings/idna.py", line 165, in encode
raise UnicodeError("label empty or too long")
UnicodeError: label empty or too long
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 122, in <module>
shortcut = shortcut_handler(line)
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 864, in shortcut_handler
ret = factory(shortcut)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 430, in shortcut_handler
return PPAShortcutHandler(shortcut)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 387, in __init__
info = get_ppa_info(self.shortcut)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 370, in get_ppa_info
_get_suggested_ppa_message(user, ppa))
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 327, in _get_suggested_ppa_message
lp_user = get_info_from_lp(LAUNCHPAD_USER_API % user)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 88, in get_info_from_lp
return _get_https_content_py3(lp_url)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 112, in _get_https_content_py3
lp_page = urllib.request.urlopen(request, cafile=LAUNCHPAD_PPA_CERT)
File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.5/urllib/request.py", line 466, in open
response = self._open(req, data)
File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
'_open', req)
File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/usr/lib/python3.5/urllib/request.py", line 1297, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "/usr/lib/python3.5/http/client.py", line 1107, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
self.send(msg)
File "/usr/lib/python3.5/http/client.py", line 877, in send
self.connect()
File "/usr/lib/python3.5/http/client.py", line 1253, in connect
super().connect()
File "/usr/lib/python3.5/http/client.py", line 849, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/lib/python3.5/socket.py", line 694, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.5/socket.py", line 733, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)
This doesn't look like a Unicode problem or a Python problem. It looks like an error in the PPA.
But you need to give more information to let us truly help you. For instance, which PPA are you installing? Has it installed successfully on another system?
While installing the Google Cloud SDK - Python, a httplib2.SSLHandshakeError keeps occuring. I have configured the unfilled_client_secrets.json (shown below the return). And this has not solved the HandshakeError.
Similar questions have been asked on here below, but none have been explicitly answered. Thank you, in advance for any help you might be able to provide.
~ $ ./google-cloud-sdk/install.sh Welcome to the Google Cloud SDK!
Traceback (most recent call last):
File
"/Users/rptrainor/./google-cloud-sdk/bin/bootstrapping/install.py",
line 206, in
main()
File "/Users/rptrainor/./google-cloud-sdk/bin/bootstrapping/install.py",
line 184, in main
Install(pargs.override_components, pargs.additional_components)
File
"/Users/rptrainor/./google-cloud-sdk/bin/bootstrapping/install.py",
line 130, in Install
_CLI.Execute(['--quiet', 'components', 'list'])
File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py",
line 759, in Execute
self._HandleAllErrors(exc, command_path_string, specified_arg_names)
File
"/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py",
line 737, in Execute
resources = args.calliope_command.Run(cli=self, args=args)
File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py",
line 741, in Run
display_info=self.ai.display_info).Display()
File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/calliope/display.py",
line 427, in Display
self._printer.Print(self._resources)
File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/core/resource/resource_printer_base.py", line 251, in Print
for resource in resources:
File "/Users/rptrainor/google-cloud-sdk/lib/surface/components/list.py",
line 86, in Run
result = update_manager.List()
File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py",
line 516, in List
_, diff = self._GetStateAndDiff(command_path='components.list')
File
"/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py",
line 446, in _GetStateAndDiff
command_path=command_path)
File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py",
line 429, in _GetLatestSnapshot
*effective_url.split(','), command_path=command_path)
File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/core/updater/snapshots.py",
line 165, in FromURLs
for url in urls]
File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/core/updater/snapshots.py",
line 186, in _DictFromURL
response = installers.ComponentInstaller.MakeRequest(url, command_path)
File
"/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/core/updater/installers.py",
line 283, in MakeRequest
return url_opener.urlopen(req, timeout=timeout)
File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/core/url_opener.py",
line 69, in urlopen
return opener.open(req, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 404, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 422, in _open
'_open', req) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 382, in _call_chain
result = func(*args) File "/Users/rptrainor/google-cloud-sdk/lib/googlecloudsdk/core/url_opener.py",
line 54, in https_open
return self.do_open(build, req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
line 1181, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers) File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 995, in request
self._send_request(method, url, body, headers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 1029, in _send_request
self.endheaders(body)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 991, in endheaders
self._send_output(message_body)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 844, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 806, in send
self.connect()
File "/Users/rptrainor/google-cloud-sdk/lib/third_party/httplib2/init.py",
line 1081, in connect
raise SSLHandshakeError(e)
httplib2.SSLHandshakeError: [Errno 1] _ssl.c:510: error:14090086:SSL >routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
{
"web":{
"client_id":"[[CLIENT_ID_IS_HERE]]",
"project_id":"[[PROJECT_ID_IS_HERE]]",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"[[CLIENT_SECRET_IS_HERE]]"
}
}
Try updating Python to the last 2.7.x version. I could resolve the very same issue updating Python to 2.7.13.
One silly yet effective solution could be accessing these URL's via browser once and accepting their certificate.
As well check the time of your computer. If it is not appropriate i mean not in the current date. Server will not share the certificate.
i'm trying to open an url http://الاعلي-للاتصالات.قطر/ar/news-events/event/future-internet-privacy
with the urllib2.urlopen but it reports always an error.
The similar occurs to http://الاعلي-للاتصالات.قطر/ar ... other pages (chinese ones) are opened ok.
Any ideas to point me to the right way to open those urls?
urllib2.urlopen("http://الاعلي-للاتصالات.قطر/ar/news-events/event/future-internet-privacy").read()
urllib2.urlopen('http://الاعلي-للاتصالات.قطر').read()
[Edited]
the error is :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.6/urllib2.py", line 391, in open
response = self._open(req, data)
File "/usr/lib/python2.6/urllib2.py", line 409, in _open
'_open', req)
File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib/python2.6/urllib2.py", line 1170, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.6/urllib2.py", line 1142, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "/usr/lib/python2.6/httplib.py", line 914, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.6/httplib.py", line 951, in _send_request
self.endheaders()
File "/usr/lib/python2.6/httplib.py", line 908, in endheaders
self._send_output()
File "/usr/lib/python2.6/httplib.py", line 780, in _send_output
self.send(msg)
File "/usr/lib/python2.6/httplib.py", line 759, in send
self.sock.sendall(str)
I also tried with the u'http://الاعلي-للاتصالات.قطر'.encode('utf-8') but the result url can't be opened too.
As #Donal says, the URL has to be punycoded. Luckily Python includes this already. Here is a sample Python code
domain = "الاعلي-للاتصالات.قطر"
domain_unicode = unicode(domain, "utf8")
domain_idna = domain_unicode.encode("idna")
urllib2.urlopen("http://" + domain_idna).read()
Hope this helps.