Python RecursionError raised Requests 2.26 and Firebase 5.1 - python-3.x

Since a week I'm facing a weird bug on my python server.
Right now it is running on Requests version 2.23.0 without issue.
Because of vulnerability issue I'd like to bump the Requests version to the 2.26.0.
My servers runs ok until I try to run a piece of code like that:
import requests
from firebase_admin import auth
bearer_token = requests.headers['X-Bearer-Token'] # Usually there is the word `Bearer`, consider we remove it.
decoded_token = auth.verify_id_token(bearer_token, check_revoked=False)
This piece of code will raise:
RecursionError: maximum recursion depth exceeded
Full error:
Traceback (most recent call last):
File "./project/handlers/users.py", line 106, in get_user
decoded_token = auth.verify_id_token(a, check_revoked=False)
File "./project/venv/lib/python3.6/site-packages/firebase_admin/auth.py", line 220, in verify_id_token
return client.verify_id_token(id_token, check_revoked=check_revoked)
File "./project/venv/lib/python3.6/site-packages/firebase_admin/_auth_client.py", line 127, in verify_id_token
verified_claims = self._token_verifier.verify_id_token(id_token)
File "./project/venv/lib/python3.6/site-packages/firebase_admin/_token_gen.py", line 293, in verify_id_token
return self.id_token_verifier.verify(id_token, self.request)
File "./project/venv/lib/python3.6/site-packages/firebase_admin/_token_gen.py", line 396, in verify
certs_url=self.cert_url)
File "./project/venv/lib/python3.6/site-packages/google/oauth2/id_token.py", line 124, in verify_token
certs = _fetch_certs(request, certs_url)
File "./project/venv/lib/python3.6/site-packages/google/oauth2/id_token.py", line 98, in _fetch_certs
response = request(certs_url, method="GET")
File "./project/venv/lib/python3.6/site-packages/firebase_admin/_token_gen.py", line 266, in __call__
url, method=method, body=body, headers=headers, timeout=timeout, **kwargs)
File "./project/venv/lib/python3.6/site-packages/google/auth/transport/requests.py", line 184, in __call__
method, url, data=body, headers=headers, timeout=timeout, **kwargs
File "./project/venv/lib/python3.6/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "./project/venv/lib/python3.6/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "./project/venv/lib/python3.6/site-packages/cachecontrol/adapter.py", line 57, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "./project/venv/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "./project/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "./project/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "./project/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
conn.connect()
File "./project/venv/lib/python3.6/site-packages/urllib3/connection.py", line 332, in connect
cert_reqs=resolve_cert_reqs(self.cert_reqs),
File "./project/venv/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 281, in create_urllib3_context
context.options |= options
File "/usr/local/lib/python3.6/ssl.py", line 465, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.6/ssl.py", line 465, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.6/ssl.py", line 465, in options
super(SSLContext, SSLContext).options.__set__(self, value)
[Previous line repeated 963 more times]
File "/usr/local/lib/python3.6/ssl.py", line 463, in options
#options.setter
RecursionError: maximum recursion depth exceeded
Librairies:
requests = ^2.24.0
firebase-admin = ^5.0.0

I solved it by removing the Eventlet Monkey patch.
eventlet.monkey_patch()

Related

Using AWS Chalice to deploy with large dependencies results in connection timeout

I am trying to use AWS Chalice to upload my Python application to a Lambda function. I need to use a number of dependencies that will exceed the 50MB limit for a Lambda app. I think I can overcome this limit by using Lambda layers for each dependency, provided each layer is below the 50MB limit. For my final app, the total unzipped deployment size is about 225 MB so it is below the 250 MB unzipped limit imposed for Lambda deployments. When I has issues with the full deployment, I decided to try increasing the size by adding dependencies. I have been successful in using Chalice to deploy an app using Lambda layers that has scipy and numpy as dependencies. The deployment size with scipy and numpy dependencies is 48.6 MB zipped and 157 MB unzipped. When I also add matplotlib the size is 66 MB zipped and 210 MB unzipped and causes an error as described below.
My requirements.txt file contains:
scipy>=1.7.0
numpy>=1.19.2
matplotlib>=3.5.0
My chalice config file contains:
{
"automatic_layer": true,
"stages": {
"dev": {
"api_gateway_stage": "api"
}
},
"version": "2.0",
"app_name": "demoapp"
}
My chalice app code looks like this:
from chalice import Chalice
app = Chalice(app_name='demoapp')
app.debug = True
#app.lambda_function()
def numpy_import(event, context):
import numpy
return {'numpy': numpy.__file__}
#app.lambda_function()
def scipy_import(event, context):
import scipy
return {'scipy': scipy.__file__}
#app.lambda_function()
def matplotlib_import(event, context):
import matplotlib
return {'matplotlib': matplotlib.__file__}
#app.route('/myapp', methods=['POST'])
def mufunction():
jsonbody = app.current_request.json_body
# extract data from json
data_array = jsonbody['data_array']
# do stuff. As a test case it is just returning what it was given.
result = data_array
# package output in json
output = {'result': result}
return output
The stack trace of the error I get is:
Creating shared layer deployment package.
Reusing existing shared layer deployment package.
Creating app deployment package.
Creating lambda layer: demoapp-dev-managed-layer
Traceback (most recent call last):
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\awsrequest.py", line 94, in _send_request
rval = super()._send_request(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\awsrequest.py", line 123, in _send_output
self.send(msg)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\awsrequest.py", line 218, in send
return super().send(str)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 971, in send
self.sock.sendall(data)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1204, in sendall
v = self.send(byte_view[count:])
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1173, in send
return self._sslobj.write(data)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\httpsession.py", line 455, in send
urllib_response = conn.urlopen(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\retry.py", line 507, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
raise value.with_traceback(tb)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\awsrequest.py", line 94, in _send_request
rval = super()._send_request(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\awsrequest.py", line 123, in _send_output
self.send(msg)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\awsrequest.py", line 218, in send
return super().send(str)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 971, in send
self.sock.sendall(data)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1204, in sendall
v = self.send(byte_view[count:])
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1173, in send
return self._sslobj.write(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionAbortedError(10053, 'An established connection was aborted by the software in your host machine', None, 10053, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\chalice\cli\__init__.py", line 636, in main
return cli(obj={})
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\click\decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\chalice\cli\__init__.py", line 189, in deploy
deployed_values = d.deploy(config, chalice_stage_name=stage)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\chalice\deploy\deployer.py", line 376, in deploy
return self._deploy(config, chalice_stage_name)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\chalice\deploy\deployer.py", line 392, in _deploy
self._executor.execute(plan)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\chalice\deploy\executor.py", line 42, in execute
getattr(self, '_do_%s' % instruction.__class__.__name__.lower(),
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\chalice\deploy\executor.py", line 55, in _do_apicall
result = method(**final_kwargs)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\chalice\awsclient.py", line 334, in publish_layer
return self._client('lambda').publish_layer_version(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\client.py", line 514, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\client.py", line 921, in _make_api_call
http, parsed_response = self._make_request(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\client.py", line 944, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 119, in make_request
return self._send_request(request_dict, operation_model)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 202, in _send_request
while self._needs_retry(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 354, in _needs_retry
responses = self._event_emitter.emit(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\hooks.py", line 412, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\hooks.py", line 256, in emit
return self._emit(event_name, kwargs)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\hooks.py", line 239, in _emit
response = handler(**kwargs)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 207, in __call__
if self._checker(**checker_kwargs):
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 284, in __call__
should_retry = self._should_retry(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 320, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 363, in __call__
checker_response = checker(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 247, in __call__
return self._check_caught_exception(
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 416, in _check_caught_exception
raise caught_exception
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 281, in _do_get_response
http_response = self._send(request)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 377, in _send
return self.http_session.send(request)
File "C:\Users\Matthew Reid\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\httpsession.py", line 494, in send
raise ConnectionClosedError(
botocore.exceptions.ConnectionClosedError: Connection was closed before we received a valid response from endpoint URL: "https://lambda.ap-southeast-2.amazonaws.com/2018-10-31/layers/demoapp-dev-managed-layer/versions".
I think this error is a connection timeout issue caused by my computer. I have tried to fix this by adjusting the DEFAULT_TIMEOUT variable in botocore from 60 to 600. I also deploy with the command “chalice deploy --connection-timeout 600”.
My internet upload speed is approximately 5 MB/s so for a 66 MB file it should manage that in about 15 seconds.
If you have any suggestions about how to deploy an app that has multiple python dependancies that exceed 50MB when zipped, then I’d love to know your solution.
For reference, I have looked at these similar questions:
How to deploy projects with larger dependencies and exceeding deployment limits on AWS Lambda function?
boto3 ConnectionClosedError python

Python SDK for Vmware get stuck in openSSL SSL_read

I am using [Python SDK][1] for VMware automation tasks e.g. power off, power on and delete VMs in vcenter server.
from com.vmware.vcenter.vm_client import Power
from samples.vsphere.vcenter.helper.vm_helper import get_vm
import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
import argparse
Inputs = fetch_inputs()
vm_name = Inputs.VM_Name
action = Inputs.action
session = requests.session()
# Disable cert verification for demo purpose.
# This is not recommended in a production environment.
session.verify = False
# Disable the secure connection warning for demo purpose.
# This is not recommended in a production environment.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Connect to a vCenter Server using username and password
vsphere_client = create_vsphere_client(server=Inputs.server, username=Inputs.username, password=Inputs.password, session=session)
vsphere_client.vcenter.vm.Power.stop(vm) <<--- It gets stuck here.
However, it does the operation but after that it gets stuck there and never comes out. If I do CTRL+C, then I can see that it seemd to get stuck in SSL_read in OpenSSL library:
^CTraceback (most recent call last):
File "/home/qa1/python_sdk_scripts/manage_vm.py", line 97, in <module>
power_on(vsphere_client, vm_name)
File "/home/qa1/python_sdk_scripts/manage_vm.py", line 40, in power_on
return_value = vsphere_client.vcenter.vm.Power.start(vm)
File "/home/qa1/.local/lib/python3.8/site-packages/com/vmware/vcenter/vm_client.py", line 2141, in start
return self._invoke('start',
File "/home/qa1/.local/lib/python3.8/site-packages/vmware/vapi/bindings/stub.py", line 345, in _invoke
return self._api_interface.native_invoke(ctx, _method_name, kwargs)
File "/home/qa1/.local/lib/python3.8/site-packages/vmware/vapi/bindings/stub.py", line 266, in native_invoke
method_result = self.invoke(ctx, method_id, data_val)
File "/home/qa1/.local/lib/python3.8/site-packages/vmware/vapi/bindings/stub.py", line 199, in invoke
return self._api_provider.invoke(self._iface_id.get_name(),
File "/home/qa1/.local/lib/python3.8/site-packages/vmware/vapi/security/client/security_context_filter.py", line 101, in invoke
method_result = ApiProviderFilter.invoke(
File "/home/qa1/.local/lib/python3.8/site-packages/vmware/vapi/provider/filter.py", line 75, in invoke
method_result = self.next_provider.invoke(
File "/home/qa1/.local/lib/python3.8/site-packages/vmware/vapi/protocol/client/msg/json_connector.py", line 79, in invoke
response = self._do_request(VAPI_INVOKE, ctx, params)
File "/home/qa1/.local/lib/python3.8/site-packages/vmware/vapi/protocol/client/msg/json_connector.py", line 120, in _do_request
http_response = self.http_provider.do_request(
File "/home/qa1/.local/lib/python3.8/site-packages/vmware/vapi/protocol/client/rpc/requests_provider.py", line 95, in do_request
output = self._session.request(
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 421, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 416, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.8/http/client.py", line 1348, in getresponse
response.begin()
File "/usr/lib/python3.8/http/client.py", line 316, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.8/http/client.py", line 277, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 313, in recv_into
return self.connection.recv_into(*args, **kwargs)
File "/home/qa1/.local/lib/python3.8/site-packages/OpenSSL/SSL.py", line 1733, in recv_into
result = _lib.SSL_read(self._ssl, buf, nbytes)
KeyboardInterrupt
How can I debug this, where is the issue?
[1]: https://github.com/vmware/vsphere-automation-sdk-python

selenium alert automatically click accept with IE driver

In such this situation:
there is a list on the page
below it have one check for check all of the list item,and a div to receive all of the list,
after click it will pop up a alert,after click accept the page will close.
onclick=checkedalldoc();#check
onclick=responseclick();#div
I need use selenium with IE to automatically these
this is my basepage.py for packaging code:
# 点击元素
def click(self, *selector):
el = self.find_element(*selector)
try:
el.click()
logger.info('元素'%s' 已被点击.' % el.text)
except NameError as e:
logger.error('Failed to click the element with %s' % e)
#运行js脚本
def run_script(self, js):
try:
self.driver.execute_script(js)
logger.info('成功运行脚本,脚本内容为:%s.' % js)
except BaseException:
logger.error('js脚本运行错误.')
#切换至弹窗并点击确定
def accept_alert(self):
try:
WebDriverWait(self.driver, 20).until(EC.alert_is_present())
alert = self.driver.switch_to.alert
alert.accept()
logger.info('获得弹出框并选择确认.')
except BaseException:
logger.error('弹出框失败.')
this is logic function
def receive_all_docs(self):
self.click(*self.chkall_checkbox)
self.click(*self.response_btn)
self.accept_alert()
When it works, it prompts the following error and it does not complete the function:
Traceback (most recent call last):
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 416, in _make_request
httplib_response = conn.getresponse()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 1322, in getresponse
response.begin()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 303, in begin
version, status, reason = self._read_status()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 264, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "c:\users\a\appdata\local\programs\python\python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "e:\Dropbox\17.Develop\5.Project\autozboa\run.py", line 22, in <module>
manage()
File "e:\Dropbox\17.Develop\5.Project\autozboa\run.py", line 14, in manage
m.handle_doc() # 处理单个文件
File "e:\Dropbox\17.Develop\5.Project\autozboa\manage.py", line 67, in handle_doc
docs_unid = docs.get_docs_unid()
File "e:\Dropbox\17.Develop\5.Project\autozboa\zboa\pages\docs_page.py", line 38, in get_docs_unid
for doc in self.find_elements(*self.docs_link):
File "e:\Dropbox\17.Develop\5.Project\autozboa\zboa\framework\base_page.py", line 70, in find_elements
elements = self.driver.find_elements(*selector)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1005, in find_elements
return self.execute(Command.FIND_ELEMENTS, {
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute
return self._request(command_info[0], url, body=data)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 402, in _request
resp = http.request(method, url, body=body, headers=headers)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\request.py", line 79, in request
return self.request_encode_body(
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\request.py", line 171, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\poolmanager.py", line 330, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 719, in urlopen
retries = retries.increment(
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\util\retry.py", line 400, in increment
raise six.reraise(type(error), error, _stacktrace)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
raise value.with_traceback(tb)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 416, in _make_request
httplib_response = conn.getresponse()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 1322, in getresponse
response.begin()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 303, in begin
version, status, reason = self._read_status()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 264, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "c:\users\a\appdata\local\programs\python\python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None))
i would try two things here
first, syntax:
as described in selenium-python docs, accepting alert is done by:
from selenium.webdriver.common.alert import Alert
Alert(driver).accept()
second, you should check exectly which row produces the exception.
UnexpectedAlertPresentException occurs when you are trying to preform an action while an alert is open. is it possible that those "click" actions are called when an alert is already open?

Certificate Error when using wikipedia API in python 3.7

When I'm trying to use the Wikipedia API, I get a certificate error message.
This for an assistant I am coding on a school computer and I think it is something that has been put there by administration as I got a certificate error when using NPM previously.
Here is the code I am using:
wikiSearch = query.strip("wiki ")
outputs = wikipedia.summary(wikiSearch, sentences=3)
I thought this would return the first three sentences of the article as it does in python 2.7 but instead returns this lengthy error message:
Traceback (most recent call last):
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/urllib3/connectionpool.py", line 344, in _make_request
self._validate_conn(conn)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn
conn.connect()
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/urllib3/connection.py", line 350, in connect
ssl_context=context)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/urllib3/util/ssl_.py", line 355, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/urllib3/connectionpool.py", line 641, in urlopen
_stacktrace=sys.exc_info()[2])
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/urllib3/util/retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='en.wikipedia.org', port=443): Max retries exceeded with url: /w/api.php?list=search&srprop=&srlimit=1&limit=1&srsearch=alex&srinfo=suggestion&format=json&action=query (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "dave.py", line 54, in <module>
index()
File "dave.py", line 24, in index
outputs = wikipedia.summary(wikiSearch, sentences=3)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/util.py", line 28, in __call__
ret = self._cache[key] = self.fn(*args, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/wikipedia.py", line 231, in summary
page_info = page(title, auto_suggest=auto_suggest, redirect=redirect)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/wikipedia.py", line 270, in page
results, suggestion = search(title, results=1, suggestion=True)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/util.py", line 28, in __call__
ret = self._cache[key] = self.fn(*args, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/wikipedia.py", line 103, in search
raw_results = _wiki_request(search_params)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/wikipedia.py", line 737, in _wiki_request
r = requests.get(API_URL, params=params, headers=headers)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/sessions.py", line 668, in send
history = [resp for resp in gen] if allow_redirects else []
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/sessions.py", line 668, in <listcomp>
history = [resp for resp in gen] if allow_redirects else []
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/sessions.py", line 247, in resolve_redirects
**adapter_kwargs
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='en.wikipedia.org', port=443): Max retries exceeded with url: /w/api.php?list=search&srprop=&srlimit=1&limit=1&srsearch=alex&srinfo=suggestion&format=json&action=query (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))
Edit:
I now get this error:
File "/Users/alexander.hawking/Desktop/Dave/dave.py", line 84, in <module>
index()
File "/Users/alexander.hawking/Desktop/Dave/dave.py", line 26, in index
outputs = wikipedia.summary(wikiSearch, sentences=3)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/util.py", line 28, in __call__
ret = self._cache[key] = self.fn(*args, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/wikipedia.py", line 231, in summary
page_info = page(title, auto_suggest=auto_suggest, redirect=redirect)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/wikipedia.py", line 270, in page
results, suggestion = search(title, results=1, suggestion=True)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/util.py", line 28, in __call__
ret = self._cache[key] = self.fn(*args, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/wikipedia.py", line 103, in search
raw_results = _wiki_request(search_params)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/wikipedia/wikipedia.py", line 737, in _wiki_request
r = requests.get(API_URL, params=params, headers=headers)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/alexander.hawking/Library/Python/3.7/lib/python/site-packages/requests/adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPConnectionPool(host='myproxy.proxy.com', port=1234): Max retries exceeded with url: http://en.wikipedia.org/w/api.php?list=search&srprop=&srlimit=1&limit=1&srsearch=alex&srinfo=suggestion&format=json&action=query (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10e2d3eb8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')))
As you have mentioned that you encountered a similar error when you were working with NPM, it's most likely due to the proxy setup by your administration.
You can configure the proxy for any third party module to connect to the internet. By default, urlopen of urllib3 uses the environment variable http_proxy to determine which HTTP proxy to use.
run this command in CMD before running your python application
export http_proxy='http://myproxy.proxy.com:1234'
============================================================
if you don't know your proxy you can try this workaround.
run this command in CMD before running the python application
export CURL_CA_BUNDLE=''
or add these lines to your code to avoid adding environment variable manually every time.
import os
os.environ['CURL_CA_BUNDLE'] = ""
if you are getting InsecureRequestWarning and you want to suppress it you can do the following.
import wikipedia
import os
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
os.environ['CURL_CA_BUNDLE'] = ""
os.environ['PYTHONWARNINGS']="ignore:Unverified HTTPS request"
print(wikipedia.wikipedia.summary("Google"))
I hope this helps.

Fail to install pip in Python3.6

When I wanted to install pip, the error just came out:
C:\Users\xd>python get-pip.py install
Collecting install
Exception:
Traceback (most recent call last):
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\commands\install.py", line 324, in run
requirement_set.prepare_files(finder)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\req\req_set.py", line 554, in _prepare_file
require_hashes
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\req\req_install.py", line 278, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\index.py", line 568, in _get_pages
page = self._get_page(location)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\index.py", line 792, in get_page
"Cache-Control": "max-age=600",
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\requests\sessions.py", line 488, in get
return self.request('GET', url, **kwargs)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\download.py", line 386, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\requests\sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\requests\sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\cachecontrol\adapter.py", line 47, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\requests\adapters.py", line 423, in send
timeout=timeout
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 589, in urlopen
self._prepare_proxy(conn)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 797, in _prepare_proxy
conn.connect()
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\requests\packages\urllib3\connection.py", line 254, in connect
conn = self._new_conn()
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\requests\packages\urllib3\connection.py", line 142, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "C:\Users\xd\AppData\Local\Temp\tmpf2uneu6f\pip.zip\pip\_vendor\requests\packages\urllib3\util\connection.py", line 66, in create_connection
if host.startswith('['):
AttributeError: 'NoneType' object has no attribute 'startswith'
What can I do?
For recent Python versions (3.4+), you don't need to use the get-pip.py script anymore. Just run python -m ensurepip, and the ensurepip module will do everything the get-pip.py script used to do.

Resources