python 内置函数 new_Python httplib2 AttributeError:“内置函数”或“方法”对象没有属性“new”...
时间: 2023-11-10 20:05:28 浏览: 100
在 Python 中,内置函数 `new` 已经在 Python 3 中被移除了。如果你遇到了类似 `AttributeError: 'builtin_function_or_method' object has no attribute 'new'` 的错误,很可能是因为你使用了旧版本的代码,而该代码在 Python 3 中已经不再被支持。
如果你使用 `new` 函数来创建一个对象,可以考虑使用 Python 中的 `object.__new__()` 方法代替。例如,如果你要创建一个新的字符串对象,可以使用以下代码:
```
s = str.__new__(str)
```
另外,如果你使用的是 httplib2 模块,你可以检查一下你的代码是否有错误。因为 httplib2 模块并不会使用 `new` 函数或方法。可能是其他地方的问题导致了该错误的出现。
相关问题
Traceback (most recent call last): File "D:\02-study\python_scripts\load\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen httplib_response = self._make_request( File "D:\02-study\python_scripts\load\venv\lib\site-packages\urllib3\connectionpool.py", line 398, in _make_request conn.request(method, url, **httplib_request_kw) File "D:\02-study\python_scripts\load\venv\lib\site-packages\urllib3\connection.py", line 239, in request super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "D:\02-study\python\lib\http\client.py", line 1282, in request self._send_request(method, url, body, headers, encode_chunked) File "D:\02-study\python\lib\http\client.py", line 1328, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "D:\02-study\python\lib\http\client.py", line 1277, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "D:\02-study\python\lib\http\client.py", line 1037, in _send_output self.send(msg) File "D:\02-study\python\lib\http\client.py", line 975, in send self.connect() File "D:\02-study\python_scripts\load\venv\lib\site-packages\urllib3\connection.py", line 205, in connect conn = self._new_conn() File "D:\02-study\python_scripts\load\venv\lib\site-packages\urllib3\connection.py", line 186, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001CC3180D4B0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\02-study\python_scripts\load\venv\lib\site-packages\requests\adapters.py", line 489, in send resp = conn.urlopen( File "D:\02-study\python_scripts\load\venv\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen retries = retries.increment( File "D:\02-study\python_scripts\load\venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='uem-uat.yun.hihonor.com', port=80): Max retries exceeded with url: /uem-gateway/analytics-metrics/services/user-access-detail/access-list/1/10?t=1679290718262 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001CC3180D4B0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\02-study\python_scripts\load\script\code_validate.py", line 61, in <module> res = q.query(role_code='China_Area#Country Representative') File "D:\02-study\python_scripts\load\script\code_validate.py", line 54, in query res = self.sess.request('post', url=url_pro, headers=header, json=json) File "D:\02-study\python_scripts\load\venv\lib\site-packages\requests\sessions.py", line 587, in request resp = self.send(prep, **send_kwargs) File "D:\02-study\python_scripts\load\venv\lib\site-packages\requests\sessions.py", line 701, in send r = adapter.send(request, **kwargs) File "D:\02-study\python_scripts\load\venv\lib\site-packages\requests\adapters.py", line 565, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='uem-uat.yun.hihonor.com', port=80): Max retries exceeded with url: /uem-gateway/analytics-metrics/services/user-access-detail/access-list/1/10?t=1679290718262 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001CC3180D4B0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
该错误信息显示在进行HTTP连接时发生错误。具体来说,发生了getaddrinfo失败的异常,导致建立新连接的过程失败。该异常发生在尝试进行对一个为'uem-uat.yun.hihonor.com'主机的80端口的HTTP连接时。该连接尝试在 '/uem-gateway/analytics-metrics/services/user-access-detail/access-list/1/10?t=1679290718262' 路径上获取访问列表。最终,该错误信息的发生导致代码验证进程无法完成。
urllib.error.URLError: <urlopen error [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1131)>signal_shutdown [atexit]
这个错误通常是由于使用的SSL/TLS版本与服务器不兼容所致。您可以尝试以下方法:
1. 确保您的Python版本和所使用的库都是最新的,因为这些问题在最新版本中可能已经得到解决。
2. 尝试更改SSL版本,您可以在代码中添加以下行来尝试使用TLSv1.2:
```
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
```
3. 如果您使用的是Python 2.x,请尝试添加以下行:
```
import httplib
httplib.HTTPSConnection._protocol_version = ssl.PROTOCOL_TLSv1
```
4. 如果您使用的是Python 3.x,请尝试添加以下行:
```
import http.client
http.client.HTTPSConnection._preferred_ssl_protocol = ssl.PROTOCOL_TLSv1
```
如果上述方法都不起作用,您可以尝试使用其他的请求库,例如Requests库,来代替urllib库。
阅读全文