I'm running into a strange issue with httplib2 and python3, I have a little script to connect to my test server, I try to disable SSL verification but it still spits out the following:
File "C:\Anaconda3\lib\site-packages\httplib2\__init__.py", line 987, in _conn_reque
conn.connect()
File "C:\Anaconda3\lib\http\client.py", line 1231, in connect
server_hostname=server_hostname)
File "C:\Anaconda3\lib\ssl.py", line 365, in wrap_socket
_context=self)
File "C:\Anaconda3\lib\ssl.py", line 583, in __init__
self.do_handshake()
File "C:\Anaconda3\lib\ssl.py", line 810, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
The code I'm using to connect:
import httplib2
url = 'https://www.MyTestServer.com/Test'
h = httplib2.Http(".cache", disable_ssl_certificate_validation=True)
h.add_credentials('username', 'password')
resp, content = h.request(url, 'GET')
Related
I am trying to run the transformers package from huggingface for text generation in python 3.8.2 on my company laptop.
The code is as follows:
from transformers import pipeline, set_seed
generator = pipeline('text-generation', model='gpt2')
But I am getting this SSL certificate error.
Traceback (most recent call last):
File "C:\Users\mss\Work\RI_Demo\myvenv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\mss\Work\RI_Demo\myvenv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "C:\Users\mss\Work\RI_Demo\myvenv\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
conn.connect()
File "C:\Users\mss\Work\RI_Demo\myvenv\lib\site-packages\urllib3\connection.py", line 416, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\mss\Work\RI_Demo\myvenv\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\mss\Work\RI_Demo\myvenv\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:\Python382\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Python382\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Python382\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\mss\Work\RI_Demo\myvenv\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\mss\Work\RI_Demo\myvenv\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "C:\Users\mss\Work\RI_Demo\myvenv\lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /gpt2/resolve/main/config.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')))
How can I resolve this issue?
I am writing a small Python program that involves sending emails to players in a game. I'm currently using SMTPlib to do so, and for the first while it worked great, however now I get this error whenever I try to run it:
Traceback (most recent call last):
File "/Users/user/Desktop/test.py", line 17, in <module>
sendEmail()
File "/Users/user/Desktop/test.py", line 11, in sendEmail
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 1034, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 253, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 339, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 1041, in _get_socket
new_socket = self.context.wrap_socket(new_socket,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1122)
And the bare-bones code that throws this error:
import smtplib, ssl
def sendEmail():
port = 465 # For SSL
password = 'password'
senderEmail = 'senderEmail#email.com'
# Create a secure SSL context
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
server.login(senderEmail, password)
message = 'Hello world!'
server.sendmail(senderEmail, 'myEmail#email.com', message)
sendEmail()
I suspect that this error has to do with me using Python 3.9.0 instead of 3.7.6 as that is the only thing that has changed about my environment since the last time it was working, but I'm not certain about that*. What is causing this error, and what can I do to fix it?
*EDIT: I ran the same code on Python 3.7.6 in case that was the problem. Interestingly, it now gives a very similar error:
Traceback (most recent call last):
File "test.py", line 17, in <module>
sendEmail()
File "test.py", line 11, in sendEmail
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 1031, in __init__
source_address)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 1039, in _get_socket
server_hostname=self._host)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)
I have been trying to use requests-html in a venv environment (python 3.7.0 - MacOS 10.15.1), however I am dealing with some certificate issue (I'm not behind any proxy/firewall):
The main call is :
from requests_html import HTMLSession
sessao = HTMLSession()
r1 = sessao.get(url=url_inicio)
The exception is raised while running the GET method, like this:
/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/bin/python "/Users/ricardobarroslourenco/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/192.6817.19/PyCharm.app/Contents/helpers/pydev/pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 50377 --file /Users/ricardobarroslourenco/PycharmProjects/zarc/zarc_scraper/main.py
pydev debugger: process 9369 is connecting
Connected to pydev debugger (build 192.6817.19)
[W:pyppeteer.chromium_downloader] start chromium download.
Download may take a few minutes.
Traceback (most recent call last):
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
conn.connect()
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/connection.py", line 394, in connect
ssl_context=context,
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 370, 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 850, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/requests_html.py", line 714, in browser
self._browser = await pyppeteer.launch(ignoreHTTPSErrors=not(self.verify), headless=True, args=self.__browser_args)
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/pyppeteer/launcher.py", line 311, in launch
return await Launcher(options, **kwargs).launch()
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/pyppeteer/launcher.py", line 125, in __init__
download_chromium()
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/pyppeteer/chromium_downloader.py", line 136, in download_chromium
extract_zip(download_zip(get_url()), DOWNLOADS_FOLDER / REVISION)
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/pyppeteer/chromium_downloader.py", line 78, in download_zip
data = http.request('GET', url, preload_content=False)
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/request.py", line 76, in request
method, url, fields=fields, headers=headers, **urlopen_kw
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/request.py", line 97, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/poolmanager.py", line 330, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 760, in urlopen
**response_kw
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 760, in urlopen
**response_kw
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 760, in urlopen
**response_kw
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/Users/ricardobarroslourenco/PycharmProjects/zarc/venv/lib/python3.7/site-packages/urllib3/util/retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='storage.googleapis.com', port=443): Max retries exceeded with url: /chromium-browser-snapshots/Mac/575458/chrome-mac.zip (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)')))
Any hints on how to solve this issue? The idea is to scrape some websites which cookies are generated with javascript, and requests-html supposedly solves the problem of renderization (that occurs on the regular requests package).
this is my code:
import requests
param = {
"username" : "login",
"password" : "password",
}
header = {
"content-type":"application/x-www-form-urlencoded"
}
r=requests.post("https://adres/rest/token", headers=header,params=param)
print(r.status_code)
And this is a result of this code:
Traceback (most recent call last):
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 849, in _validate_conn
conn.connect()
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 356, in connect
ssl_context=context)
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\ssl_.py", line 372, in ssl_wrap_socket
return context.wrap_socket(sock)
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 412, in wrap_socket
session=session
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 850, in _create
self.do_handshake()
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)
I am trying to get a token from Security center using API and python3 according to documentation I need to issue a content type and credentials, but like above it is not working :(
It seems like API you're calling has self-signed certificate. Workaround you can use in this case:
r=requests.post("https://adres/rest/token", headers=header,params=param, verify=False)
verify=False would not check SSL certificate for validity.
When I set verify = False I get a 200 response. When I set verify = True I get an SSL error. I updated certifi and opensll, but not sure what to do next. I am using Anaconda on Windows. I believe I need to download the domain validation certificate as *.crt or *pem file from https://api.seatgeek.com/2/events?client_id=MYCLIENTID, but not sure how to do that exactly.
Traceback (most recent call last):
File "C:\Anaconda\envs\seatgeek\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "C:\Anaconda\envs\seatgeek\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "C:\Anaconda\envs\seatgeek\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn
conn.connect()
File "C:\Anaconda\envs\seatgeek\lib\site-packages\urllib3\connection.py", line 326, in connect
ssl_context=context)
File "C:\Anaconda\envs\seatgeek\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Anaconda\envs\seatgeek\lib\ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "C:\Anaconda\envs\seatgeek\lib\ssl.py", line 808, in __init__
self.do_handshake()
File "C:\Anaconda\envs\seatgeek\lib\ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "C:\Anaconda\envs\seatgeek\lib\ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Anaconda\envs\seatgeek\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
File "C:\Anaconda\envs\seatgeek\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Anaconda\envs\seatgeek\lib\site-packages\urllib3\util\retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.seatgeek.com', port=443): Max retries exceeded with url: (Caused by SSLError(SSLError(1, '[SSL: CERT
IFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),))
import requests
with open("id.txt","r") as file:
read_data = file.readlines()
client_id_data = read_data[1]
CLIENT_ID = client_id_data
payload = {'performers[home_team].slug': 'warriors','client_id':
CLIENT_ID}
response = requests.get('https://api.seatgeek.com/2/events', verify = True,
params=payload)
you can export certificate for the link https://api.seatgeek.com/2/events?client_id=MYCLIENTID using chrome/firefox browser , here is a wikihow link https://www.wikihow.com/Export-Certificate-Public-Key-from-Chrome