代码
from solcx import compile_standard, install_solc # solc是一个编译器
import solcx
import json
with open("./SimpleStorage.sol", "r") as file:
Simple_Storage_file = file.read()
# Complie our solidity
solcx.install_solc("0.6.0")
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": Simple_Storage_file}},
"settings": {
"outputSelection": {
"*": {
"*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]
}
}
},
},
solc_version="0.6.0",
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file) # 将python中的对象转化成json储存到文件中
问题
1. ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:997)
违反协议
Traceback (most recent call last):
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connectionpool.py", line 700, in urlopen
self._prepare_proxy(conn)
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connectionpool.py", line 996, in _prepare_proxy
conn.connect()
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connection.py", line 364, in connect
self.sock = conn = self._connect_tls_proxy(hostname, conn)
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connection.py", line 499, in _connect_tls_proxy
socket = ssl_wrap_socket(
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\util\ssl_.py", line 453, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\util\ssl_.py", line 495, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock)
File "N:\ppython\pythonn\lib\ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "N:\ppython\pythonn\lib\ssl.py", line 1070, in _create
self.do_handshake()
File "N:\ppython\pythonn\lib\ssl.py", line 1341, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:997)
原因:开着代理
2. 关闭代理后出现以下错误
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='solc-bin.ethereum.org', port=443): Max retries exceeded with url: /windows-amd64/list.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000216AB1AEB60>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))
Traceback (most recent call last):
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\util\connection.py", line 72, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "N:\ppython\pythonn\lib\socket.py", line 955, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11002] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request self._validate_conn(conn)
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connection.py", line 358, in connect
self.sock = conn = self._new_conn()
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x00000216AB1AEB60>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='solc-bin.ethereum.org', port=443): Max retries exceeded with url: /windows-amd64/list.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000216AB1AEB60>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "N:\ppython\pythonn\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "N:\ppython\pythonn\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
install_solc(args.version, solcx_binary_path=args.solcx_binary_path)
data = requests.get(BINARY_DOWNLOAD_BASE.format(_get_os_name(), "list.json"))
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\requests\api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "N:\ppython\file\venv\solidity_web3_venv\Lib\site-packages\requests\adapters.py", line 565, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='solc-bin.ethereum.org', port=443): Max retries exceeded with url: /windows-amd64/list.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000216AB1AEB60>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))
原因:
solcx.install_solc("0.6.0") 下载这步出现了
解决:
solc-bin.ethereum.org 已经停止维护了
需要换成这个 binaries.soliditylang.org
解决!!!!!!
参考:(27条消息) brownie ConnectionError: Solc not installed and cannot connect to GitHub_十倍的快乐的博客-CSDN博客