Answer the question
In order to leave comments, you need to log in
How to solve python error?
error with this ssl, spent 3-4 hours did not solve it. Help.
Bot for VK
Code
# -*- coding: utf-8 -*-
import requests
import vk_api
from vk_api import VkUpload
from vk_api.longpoll import VkLongPoll, VkEventType
def main():
session = requests.Session()
login, password = 'мой логин', 'мой пароль'
vk_session = vk_api.VkApi(login, password)
try:
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
vk = vk_session.get_api()
longpoll = VkLongPoll(vk_session)
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
print('id{}: "{}"'.format(event.user_id, event.text), end=' ')
attachments = []
text = 'Ты сказал "{}"'.format(event.text)
vk.messages.send(
user_id=event.user_id,
attachment=','.join(attachments),
message=text
)
print('ok')
if __name__ == '__main__':
main()
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 578, in urlopen
chunked=chunked)
File "C:\Python36\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 351, in _make_request
self._validate_conn(conn)
File "C:\Python36\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 814, in _validate_conn
conn.connect()
File "C:\Python36\lib\site-packages\requests\packages\urllib3\connection.py", line 289, in connect
ssl_version=resolved_ssl_version)
File "C:\Python36\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 308, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Python36\lib\ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "C:\Python36\lib\ssl.py", line 814, in __init__
self.do_handshake()
File "C:\Python36\lib\ssl.py", line 1068, in do_handshake
self._sslobj.do_handshake()
File "C:\Python36\lib\ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\requests\adapters.py", line 403, in send
timeout=timeout
File "C:\Python36\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 604, in urlopen
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\asus\Desktop\take\vk-bot.py", line 40, in <module>
main()
File "C:\Users\asus\Desktop\take\vk-bot.py", line 16, in main
vk_session.auth(token_only=True)
File "C:\Users\asus\AppData\Roaming\Python\Python36\site-packages\vk_api\vk_api.py", line 169, in auth
self._auth_token(reauth=reauth)
File "C:\Users\asus\AppData\Roaming\Python\Python36\site-packages\vk_api\vk_api.py", line 220, in _auth_token
self._vk_login()
File "C:\Users\asus\AppData\Roaming\Python\Python36\site-packages\vk_api\vk_api.py", line 241, in _vk_login
response = self.http.get('https://vk.com/')
File "C:\Python36\lib\site-packages\requests\sessions.py", line 487, in get
return self.request('GET', url, **kwargs)
File "C:\Python36\lib\site-packages\requests\sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python36\lib\site-packages\requests\sessions.py", line 585, in send
r = adapter.send(request, **kwargs)
File "C:\Python36\lib\site-packages\requests\adapters.py", line 477, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841)
[Finished in 0.7s with exit code 1]
[shell_cmd: python -u "C:\Users\asus\Desktop\take\vk-bot.py"]
[dir: C:\Users\asus\Desktop\take]
[path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Skype\Phone\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\ВСЕ ДЛЯ GULP\NODE JS\;D:\GIT\Git\cmd;C:\Python36\Scripts\;C:\Python36\;D:\Python\Python36\Scripts\;D:\Python\Python36\;C:\Users\asus\AppData\Local\Microsoft\WindowsApps;C:\Users\asus\AppData\Roaming\npm]
Answer the question
In order to leave comments, you need to log in
It is worth checking the Python version and immediately updating all packages, in particular urllib, requests and the vk wrapper.
Pihon doesn't like the site's certificate. It probably doesn't know the auth authority that signed that site's certificate. Pihon needs to specify the CA certificate in the ssl context. Or add the CA certificate to the pihon's certificate store (ask pip to put a package of something like ca-certificates, all root new ones are there). Or ask them to ignore stupid certificates and not complain about them.
The point is that pihon doesn't use the OS certificate store normally.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question