Repository navigation
Closed
Description
build
cargo build --release --all-features
RustPython
import urllib.request
req = urllib.request.Request(url="https://www.httpbin.org")
html = urllib.request.urlopen(req).read().decode()
print(html)output
D:\RustPython\target\release (main -> origin)
λ rustpython.exe
Welcome to the magnificent Rust Python 0.1.2 interpreter � �
>>>>> import urllib.request
>>>>> req = urllib.request.Request(url="https://www.httpbin.org")
>>>>> html = urllib.request.urlopen(req).read().decode()
Traceback (most recent call last):
File "urllib.request", line 1355, in do_open
File "http.client", line 1239, in request
File "http.client", line 1285, in _send_request
File "http.client", line 1234, in endheaders
File "http.client", line 1026, in _send_output
File "http.client", line 964, in send
File "http.client", line 1400, in connect
File "ssl", line 507, in wrap_socket
File "ssl", line 1043, in _create
File "ssl", line 1040, in _create
File "ssl", line 1311, in do_handshake
File "ssl", line 1309, in do_handshake
File "ssl", line 1309, in do_handshake
SSLError: (134, 'certificate verify failed (_ssl.c:1915)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "urllib.request", line 222, in urlopen
File "urllib.request", line 525, in open
File "urllib.request", line 543, in _open
File "urllib.request", line 502, in _call_chain
File "urllib.request", line 1398, in https_open
File "urllib.request", line 1361, in do_open
File "urllib.request", line 1357, in do_open
URLError: (134, 'certificate verify failed (_ssl.c:1915)')
>>>>> exit()
Python
D:\RustPython\target\release (main -> origin)
λ python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.request
>>> req = urllib.request.Request(url="https://www.httpbin.org")
>>> html = urllib.request.urlopen(req).read().decode()
>>> print(html)
<!DOCTYPE html>
<html lang="en">
...SSL
- code
import ssl
import urllib.request
from certifi import where, contents
req = urllib.request.Request(url="https://www.httpbin.org")
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.verify_mode = ssl.CERT_REQUIRED
ssl_context.load_verify_locations(cafile=None, capath=None, cadata=contents())
html = urllib.request.urlopen(req, context=ssl_context).read().decode()
print(html)- output
λ rustpython.exe test.py
Traceback (most recent call last):
File "urllib.request", line 1355, in do_open
File "http.client", line 1239, in request
File "http.client", line 1285, in _send_request
File "http.client", line 1234, in endheaders
File "http.client", line 1026, in _send_output
File "http.client", line 964, in send
File "http.client", line 1400, in connect
File "ssl", line 507, in wrap_socket
File "ssl", line 1043, in _create
File "ssl", line 1040, in _create
File "ssl", line 1311, in do_handshake
File "ssl", line 1309, in do_handshake
File "ssl", line 1309, in do_handshake
SSLError: (134, 'certificate verify failed (_ssl.c:1915)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 8, in <module>
html = urllib.request.urlopen(req).read().decode()
File "urllib.request", line 222, in urlopen
File "urllib.request", line 525, in open
File "urllib.request", line 543, in _open
File "urllib.request", line 502, in _call_chain
File "urllib.request", line 1398, in https_open
File "urllib.request", line 1361, in do_open
File "urllib.request", line 1357, in do_open
URLError: (134, 'certificate verify failed (_ssl.c:1915)')- I had to write the certificate to the file system and load it.
Metadata
Metadata
Assignees
Labels
No labels
Activity
cn-kali-team commentedon Sep 27, 2021
It works well in Linux, and the above problems only reappear in window.
Snowapril commentedon Sep 27, 2021
This code also works in Rustpython with linux
coolreader18 commentedon Sep 27, 2021
Oh, yea, I've known about this for a while and I've tried a couple times to figure out why it doesn't work. No luck so far; I last tried a couple months ago iirc.
oroppas commentedon Sep 27, 2021
Could https://bugs.python.org/issue36011 be related?
coolreader18 commentedon Oct 3, 2021
Oh, lol, I actually fixed this back in June but I just forgot and never opened a PR; to be fair I left for summer camp a couple days after I got it working but still 😅
Could you check if #3210 works?
cn-kali-team commentedon Oct 3, 2021
I recompiled the test and passed.
It works. Thank you for your help.