If the website I'm trying to connect to via a proxy is unsecured (HTTP), then I'm able to connect, however if it's secured (HTTPS), then I can't.
The following code works:
import urllib2
proxy_support = urllib2.ProxyHandler({'http':'xxx.xxx.xxx.xx'})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
html = urllib2.urlopen('http://www.example.com').read()
However the code below does not work,
proxy_support = urllib2.ProxyHandler({'https':'xxx.xxx.xxx.xx'})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
html = urllib2.urlopen('https://www.example.com').read()
Instead I get the following traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 61] Connection refused>
According to https://docs.python.org/2/library/urllib2.html:
Changed in version 2.7.9: cafile, capath, cadefault, and context were added.
This one allowed me to connect to my local HTTPS site that is using a self-signed SSL certificate:
html = urllib2.urlopen('http://www.example.com'),\
context=ssl._https_verify_certificates(False)
I noticed in your traceback the similarities with mine. The code, just like you posted, works on Ubuntu 14.04 (Python 2.7.6) but not in 16.04 (Python 2.7.13) with exception to the last one:
File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 429, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 447, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1241, in https_open
context=self._context)
File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>
I'm not sure if this work on your end.
Related
I am trying to deploy a helloWorld.sol using brownie. I am getting below error when I tried to run brownie run scripts/deploy.py.
Terminating local RPC client... Exception in thread Thread-5:
Traceback (most recent call last): File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connection.py",
line 175, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\util\connection.py",
line 96, in create_connection
raise err File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\util\connection.py",
line 86, in create_connection
sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused
it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py",
line 706, in urlopen
chunked=chunked, File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py",
line 394, in _make_request
conn.request(method, url, **httplib_request_kw) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connection.py",
line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "C:\Program
Files\Python37\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked) File "C:\Program Files\Python37\lib\http\client.py", line 1275, in
_send_request
self.endheaders(body, encode_chunked=encode_chunked) File "C:\Program Files\Python37\lib\http\client.py", line 1224, in
endheaders
self._send_output(message_body, encode_chunked=encode_chunked) File "C:\Program Files\Python37\lib\http\client.py", line 1016, in
_send_output
self.send(msg) File "C:\Program Files\Python37\lib\http\client.py", line 956, in send
self.connect() File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connection.py",
line 205, in connect
conn = self._new_conn() File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connection.py",
line 187, in _new_conn
self, "Failed to establish a new connection: %s" % e urllib3.exceptions.NewConnectionError:
<urllib3.connection.HTTPConnection object at 0x0000021DAA2A0F28>:
Failed to establish a new connection: [WinError 10061] No connection
could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\adapters.py",
line 449, in send
timeout=timeout File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py",
line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\util\retry.py",
line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1',
port=8545): Max retries exceeded with url: / (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000021DAA2A0F28>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\ganache.py",
line 82, in _request
response = web3.provider.make_request(method, args) # type: ignore File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\web3\providers\rpc.py",
line 91, in make_request
**self.get_request_kwargs() File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\web3_utils\request.py",
line 48, in make_post_request
response = session.post(endpoint_uri, data=data, *args, **kwargs) # type: ignore File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\sessions.py",
line 590, in post
return self.request('POST', url, data=data, json=json, **kwargs) File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\sessions.py",
line 542, in request
resp = self.send(prep, **send_kwargs) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\sessions.py",
line 655, in send
r = adapter.send(request, **kwargs) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\adapters.py",
line 516, in send
raise ConnectionError(e, request=request) requests.exceptions.ConnectionError:
HTTPConnectionPool(host='127.0.0.1', port=8545): Max retries exceeded
with url: / (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000021DAA2A0F28>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine
actively refused it'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program
Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run() File "C:\Program Files\Python37\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\state.py",
line 332, in add_to_undo_buffer
self.sleep(0) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\state.py",
line 375, in sleep
self.time_offset = int(rpc.Rpc().sleep(seconds)) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc_init.py",
line 45, in wrapped
return fn(*args, **kwargs) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc_init.py",
line 166, in sleep
return self.backend.sleep(seconds) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\ganache.py",
line 91, in sleep
return _request("evm_increaseTime", [seconds]) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\ganache.py",
line 86, in _request
raise RPCRequestError("Web3 is not connected.") brownie.exceptions.RPCRequestError: Web3 is not connected.
My deploy.py code is below.
from brownie import accounts, HelloWorld
def deployHelloWorld():
account = accounts[0]
helloWorldObject = HelloWorld.deploy({"from": account})
helloWorldObject.setName("Michael", {"from": account})
greeting = helloWorldObject.sayHello()
print(greeting)
def main():
deployHelloWorld()
could you please help?
This error is caused because there is no waiting after transaction. By using transaction.wait(1), as below, the problem is fixed.
transaction = helloWorldObject.setName("Michael", {"from": account})
transaction.wait(1)
greeting = helloWorldObject.sayHello()
print(greeting)
RPC is sometimes killed too quick, resulting in brownie.exceptions.RPCRequestError: Web3 is not connected.
Therefore you have to add the time.sleep(1) after every transaction to ensure your code runs smoothly.
You need to put after transactions
transactionVariable.wait(1)
time.sleep(1)
I know the title is a little ambiguous and I'd only ever ask here if it wasn't a last resort - but I am stuck. I've pulled down a Django project from my work repo that is rather ancient (we're talking 1.13), and I've been tasked with bringing it into 1.9. Okay, fair enough.
I've loaded the database from a MySQL dump and faked the migrations just fine. However, when I run the server, I get hit with this:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
raise err
error: [Errno 60] Operation timed out
At first, I had no idea what was going on here, but from the look of it, SMTP is throwing this exception - probably due to the mailing server not being accessible. Any how, I can't even get print statements to show up in settings.py, and so have no idea where to even start to trace this problem through.
Any guidance would be lovely.
EDIT: Here is the new error:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
response = self.get_response(request)
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/handlers/base.py", line 230, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/handlers/base.py", line 284, in handle_uncaught_exception
'request': request
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1191, in error
self._log(ERROR, msg, args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1284, in _log
self.handle(record)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1294, in handle
self.callHandlers(record)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1334, in callHandlers
hdlr.handle(record)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 757, in handle
self.emit(record)
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/utils/log.py", line 117, in emit
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/utils/log.py", line 120, in send_mail
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/mail/__init__.py", line 97, in mail_admins
mail.send(fail_silently=fail_silently)
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/mail/message.py", line 292, in send
return self.get_connection(fail_silently).send_messages([self])
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 58, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
raise err
error: [Errno 61] Connection refused
As you know, the error you were getting is because your logger was set up to send emails whenever you received an error. The problem being that your development environment doesn't have access to the mail server that this logger relies on.
What happens is django then raises this new error and the actual error gets hidden away.
The actual solution to this is to create a separate settings.py file for development, that way you don't need to worry about the mail server not being there, nor (I expect) would you really care.
When running runserver you can then specify this settings file with
runserver --settings=mysettings
For completeness, heres a very simple development settings.py file
from myapp.settings import *
print 'DEV'
DEBUG = True
# INSTALLED_APPS += ['debug_toolbar']
# MIDDLEWARE_CLASSES += ['debug_toolbar.middleware.DebugToolbarMiddleware']
I am getting:
Traceback (most recent call last):
File "/var/www/virtualenvs/myProj/local/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/var/www/virtualenvs/myProj/local/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/var/www/myProj/myProj/apps/myProj/tasks.py", line 43, in get_somestuff
str_response = urllib2.urlopen(req)
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 407, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 520, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 445, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 528, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 500: Internal Server Error
when I run task in prod server, locally it is working perfectly.
the bit is
urllib2.urlopen(req)
what may I be missing? the url I am reading is available thru browser
I'm trying to pull the source from a url in terminal and I'm getting this: As far I can tell everything is in the right place.
response = urllib2.urlopen(url)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden
i am trying to send a basic get request to "www.python.org" to fetch "www.python.org/index.html" using the httplib module in python.I use a proxy server "10.1.1.19:80".My code with the error message is shown.Please suggest me with the mistakes i'm commiting.Regards....
>>> import httplib
>>> conn=httplib.HTTPConnection("http://www.python.org",80)
>>> conn.set_tunnel("10.1.1.19:80")
>>> conn.request("GET","www.python.org/index.html",headers={"Proxy-Authorization":"Basic "+"MzEwNTMzOmdveWFs"})
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
conn.request("GET","www.python.org/index.html",headers={"Proxy-Authorization":"Basic "+"MzEwNTMzOmdveWFs"})
File "C:\Python27\lib\httplib.py", line 973, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1007, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 969, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 829, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 791, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 772, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 11004] getaddrinfo failed`
Try this
import httplib
conn = httplib.HTTPConnection("10.1.1.19", 80)
conn.request("GET", "http://www.python.org/index.html", headers={...}))