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.
Related
I am executing the below code in the python3.8 terminal which is inside of seclab VM
>>> from sentence_transformers import SentenceTransformer
>>> st_model = SentenceTransformer('sentence-transformers/sentence-t5-base')
Getting below error:
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/sentence_transformers/SentenceTransformer.py", line 87, in __init__
snapshot_download(model_name_or_path,
File "/usr/local/lib/python3.8/site-packages/sentence_transformers/util.py", line 442, in snapshot_download
model_info = _api.model_info(repo_id=repo_id, revision=revision, token=token)
File "/usr/local/lib/python3.8/site-packages/huggingface_hub/utils/_validators.py", line 94, in _inner_fn
return fn(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/huggingface_hub/utils/_deprecation.py", line 98, in inner_f
return f(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/huggingface_hub/hf_api.py", line 1283, in model_info
r = requests.get(
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 563, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/sentence-transformers/sentence-t5-base (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1131)')))
tried the below steps:
Step1:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
Step2:
os.environ["CURL_CA_BUNDLE"] = ""
The above steps didn't work for me.
Any idea how to disable the SSL certificate issue?
I'm trying to find an existing parser (preferably in Python) to write and read SysML v2.
The official Github repo by SysML v2 Submission Team (SST) has placed some examples online already (For instance https://github.com/Systems-Modeling/SysML-v2-Release/blob/master/sysml/src/examples/Vehicle%20Example/VehicleUsages.sysml ), but I'm unable to get the Eclipse Plugin running properly. (Nothing is shown in the preview windows, no error message either).
There's a repo for the SysML-v2-API-Python-Client which I installed and executed the given sample code (https://github.com/Systems-Modeling/SysML-v2-API-Python-Client), but all I'm getting is this message:
$ python3.8 Test1.py
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
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 387, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.8/http/client.py", line 1256, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1302, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output
self.send(msg)
File "/usr/lib/python3.8/http/client.py", line 951, in send
self.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 187, in connect
conn = self._new_conn()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 171, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f9492d1b9a0>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Test1.py", line 38, in <module>
api_response = api_instance.delete_branch_by_project_and_id(
File "/home/qohelet/.local/lib/python3.8/site-packages/sysml_v2_api_client-2021.post9-py3.8.egg/sysml_v2_api_client/api/branch_api.py", line 62, in delete_branch_by_project_and_id
File "/home/qohelet/.local/lib/python3.8/site-packages/sysml_v2_api_client-2021.post9-py3.8.egg/sysml_v2_api_client/api/branch_api.py", line 144, in delete_branch_by_project_and_id_with_http_info
File "/home/qohelet/.local/lib/python3.8/site-packages/sysml_v2_api_client-2021.post9-py3.8.egg/sysml_v2_api_client/api_client.py", line 364, in call_api
File "/home/qohelet/.local/lib/python3.8/site-packages/sysml_v2_api_client-2021.post9-py3.8.egg/sysml_v2_api_client/api_client.py", line 181, in __call_api
File "/home/qohelet/.local/lib/python3.8/site-packages/sysml_v2_api_client-2021.post9-py3.8.egg/sysml_v2_api_client/api_client.py", line 431, in request
File "/home/qohelet/.local/lib/python3.8/site-packages/sysml_v2_api_client-2021.post9-py3.8.egg/sysml_v2_api_client/rest.py", line 256, in DELETE
File "/home/qohelet/.local/lib/python3.8/site-packages/sysml_v2_api_client-2021.post9-py3.8.egg/sysml_v2_api_client/rest.py", line 163, in request
File "/usr/lib/python3/dist-packages/urllib3/request.py", line 75, in request
return self.request_encode_url(
File "/usr/lib/python3/dist-packages/urllib3/request.py", line 97, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "/usr/lib/python3/dist-packages/urllib3/poolmanager.py", line 330, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 747, in urlopen
return self.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 747, in urlopen
return self.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 747, in urlopen
return self.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen
retries = retries.increment(
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /projects/project_id_example/branches/branch_id_example (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9492d1b9a0>: Failed to establish a new connection: [Errno 111] Connection refused'))
Am I supposed to have anything running? Is there anywhere a tutorial or manual on how to use it?
Or are there any other parsers out there?
There are no parsers currently available for Python. The API Python Client is an example implementation to interact with the Pilot Server API Implementation. You would need to run the server to interact with the API using the python client.
I have a windows 10 machine, and I am not sure what the problem is, I was able to run everything until a few hours back and now I keep running into SSL certificate Expired error for some reason.
Steps to reproduce:
This is my code.
'''
'''
from datetime import datetime
from influxdb_client import InfluxDBClient
config = {
'start': datetime.date(datetime(2021, 4, 7)),
'stop': datetime.date(datetime(2021, 4, 10)),
'bucket': "hidden",
'org': "hidden",
'url': "hidden",
'token': "hidden",
'measurement-name': "hidden",
}
client = InfluxDBClient(
url="https://eu-central-1-1.aws.cloud2.influxdata.com",
org=config['org'],
bucket=config['bucket'],
token=config['token'],
# verify_ssl=False
)
query_api = client.query_api()
ticker = 'TSLA'
results_df = query_api.query_data_frame(
f'from(bucket:"{config["bucket"]}")'
f'|> range(start: {config["start"]}, stop: {config["stop"]}) '
'|> filter(fn: (r) =>'
f' r._measurement == "{config["measurement-name"]}"'
f' and r.symbol == "{ticker}"'
') '
'|> filter (fn: (r) =>'
' r._field == "price"'
') '
'|> pivot('
' rowKey:["_time"],'
' columnKey: ["_field"],'
' valueColumn: "_value"'
') '
'|> sort(columns: ["_time"], desc: false) '
)
print(results_df)
Expected behavior:
I expect it to give me a dataframe like it always does and as you can see when I keep the ssl_verify=False it works.
result table _time _start _stop _measurement source symbol price
0 _result 0 2021-04-07 00:00:00+00:00 2021-04-07 00:00:00+00:00 2021-04-08 00:00:00+00:00 public_instruments_data YAHOO-FINANCE TSLA 670.969971
Actual behavior:
Traceback (most recent call last):
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "d:\MAIN_ENV\lib\site-packages\urllib3\connection.py", line 411, in connect
self.sock = ssl_wrap_socket(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\rest.py", line 181, in request
r = self.pool_manager.request(
File "d:\MAIN_ENV\lib\site-packages\urllib3\request.py", line 78, in request
return self.request_encode_body(
File "d:\MAIN_ENV\lib\site-packages\urllib3\request.py", line 170, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "d:\MAIN_ENV\lib\site-packages\urllib3\poolmanager.py", line 375, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\retry.py", line 507, in increment
raise six.reraise(type(error), error, _stacktrace)
File "d:\MAIN_ENV\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "d:\MAIN_ENV\lib\site-packages\urllib3\connection.py", line 411, in connect
self.sock = ssl_wrap_socket(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\backend-dev-plaid\test_app_5.py", line 26, in <module>
results_df = query_api.query_data_frame(
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\client\query_api.py", line 146, in query_data_frame
_generator = self.query_data_frame_stream(query, org=org, data_frame_index=data_frame_index, params=params)
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\client\query_api.py", line 172, in query_data_frame_stream
response = self._query_api.post_query(org=org, query=self._create_query(query, self.default_dialect, params),
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\service\query_service.py", line 260, in post_query
(data) = self.post_query_with_http_info(**kwargs) # noqa: E501
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\service\query_service.py", line 340, in post_query_with_http_info
return self.api_client.call_api(
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\api_client.py", line 341, in call_api
return self.__call_api(resource_path, method,
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\api_client.py", line 171, in __call_api
response_data = self.request(
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\api_client.py", line 386, in request
return self.rest_client.POST(url,
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\rest.py", line 302, in POST
return self.request("POST", url,
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\rest.py", line 238, in request
raise ApiException(status=0, reason=msg)
influxdb_client.rest.ApiException: (0)
Reason: SSLError
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)
Specifications:
Client Version: 1.21.0
InfluxDB Version: 2.0
Platform: Windows 10 home
Python: 3.9.7
I tried reinstalling python and all the libraries again just make sure the problem wasn't at my end and I also followed the urllib3 docs for installing the certificates from certifi and urllib3[secure] as suggested when I keep ssl_verify=False.
Any help would be much appreciated, thanks a lot in advance.
Just use ..., ssl_ca_cert=certifi.where(), ... as a temporary solution, but anyways since posting the question it seems the certificates have been already updated.
Requests library is giving me an error I've never encountered before, while trying to download an image from my website.
Here is the download function
def dl_jpg(url, filePath, fileName):
fullPath = filePath + fileName + '.jpg'
r = requests.get(url,allow_redirects=True)
open(fullPath,'wb').write(r.content)
The URL I'm entering is:
http://www.deepfrybot.ga/uploads/c4c7936ef4218dbe7014cb543049168b.jpg
Here's the error message
Last login: Fri Nov 1 03:36:32 2019 from 116.193.136.13
__| __|_ )
_| ( / Amazon Linux 2 AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-2/
[ec2-user#ip ~]$ cd dfb-master
[ec2-user#ip dfb-master]$ sudo python3 mainr.py
enter url (n) if auto: http://www.deepfrybot.ga/uploads/c4c7936ef4218dbe7014cb543049168b.jpg
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 57, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib64/python3.7/socket.py", line 748, 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 "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 355, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib64/python3.7/http/client.py", line 1244, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib64/python3.7/http/client.py", line 1290, in _send_request
self.endheaders(body, encode_chunked=encode_chunked) File "/usr/lib64/python3.7/http/client.py", line 1239, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib64/python3.7/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/lib64/python3.7/http/client.py", line 966, in send
self.connect()
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 183, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 169, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fdce843ed50>: Failed to establish a new connection: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='www.deepfrybot.ga', port=80): Max retries exceeded with url: /uploads/c4c7936ef4218dbe7014cb543049168b.jpg (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdce843ed50>: Failed to establish a new connection: [Errno -2] Name or service not known'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "mainr.py", line 32, in wrapper
return job_func(*args, **kwargs)
File "mainr.py", line 138, in main_p
dl_jpg(url, get_abs_file('images/'), file_name)
File "mainr.py", line 67, in dl_jpg
r = requests.get(url,allow_redirects=True)
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.7/site-
packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.deepfrybot.ga', port=80): Max retries exceeded with url: /uploads/c4c7936ef4218dbe7014cb543049168b.jpg (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdce843ed50>: Failed to establish a new connection: [Errno -2] Name or service not known'))
I'm clueless as to why this is happening, a little help would be much appreciated
lxop said "
The script is failing to resolve the name 'www.deepfrybot.ga'. Does
your EC2 instance have DNS access?
"
And after checking and researching a bit on it I came to know that some specific EC2 instances/urllib3 are sometimes not able to access free top level domains (like .ga,.ml,.tk) as they have a general tendency to be malicious and also since they generally lack an SSL certificate.
These domains with SSL certificates work fine though!
And if you are hosting on say heliohost.org (which i am), simply change the domain in the script from yourwebsite.ga to yourwebsite.yourhost.domain
That should solve it!
Hello this is my first question on Stack Overflow...
I have written Python script which uses latest Python 3.7 and latest requests module.
My request queries work, however after multiple (thousands) of requests in a day, I sometimes get this stack trace and program exits. It is large stack trace and I am not sure which pieces I should investigate first. Any help would be greatly appreciated
Here is the stack trace:
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 453, in wrap_socket
cnx.do_handshake()
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1915, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1639, in _raise_ssl_error
raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (104, 'ECONNRESET')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 344, in connect
ssl_context=context)
File "/usr/lib/python3/dist-packages/urllib3/util/ssl_.py", line 344, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 459, in wrap_socket
raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: SysCallError(104, 'ECONNRESET')",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='block.io', port=443): Max retries exceeded with url: /api/v2/get_address_balance/?api_key=0d76-078a-c2c9-e524&addresses=172MQBZyt2UGfCPRwUpKCH4cmB4sRrhywy (Caused by SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')")))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Birds.py", line 291, in <module>
main()
File "Birds.py", line 287, in main
loop()
File "Birds.py", line 260, in loop
checkBTC()
File "Birds.py", line 186, in checkBTC
currentBTCBalance = getBitcoinBalance() # Check Snapy for BTC balance
File "Birds.py", line 111, in getBitcoinBalance
r = requests.get(query_url)
File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
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 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='block.io', port=443): Max retries exceeded with url: /api/v2/get_address_balance/?api_key=0d76-078a-c2c9-e524&addresses=172MQBZyt2UGfCPRwUpKCH4cmB4sRrhywy (Caused by SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')")))
I have answered my own question via these websites:
https://www.peterbe.com/plog/best-practice-with-retries-with-requests
https://realpython.com/python-requests/
Which explain how to use Transport Adapters and smart backoff. I am currently testing queries once per second and the program has been running for 24 hours without problem.