GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ssl load_verify_locations cadata can't work · Issue #3148 · RustPython/RustPython

ssl load_verify_locations cadata can't work #3148

New issue
Copy link
New issue
Copy link
Closed
Closed
ssl load_verify_locations cadata can't work#3148
Copy link

Description

@cn-kali-team
cn-kali-team
opened on Sep 27, 2021
Issue body actions

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.

Activity

  1. cn-kali-team commented on Sep 27, 2021

    @cn-kali-team
    cn-kali-team
    on Sep 27, 2021
    Author
    More actions

    It works well in Linux, and the above problems only reappear in window.

    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=where(), capath=None, cadata=None)
    
    html = urllib.request.urlopen(req, context=ssl_context).read().decode()
    print(html)
    • This works well in rustpython.
  2. Snowapril commented on Sep 27, 2021

    @Snowapril
    Snowapril
    on Sep 27, 2021
    Contributor
    More actions

    This code also works in Rustpython with linux

    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()
    >>>>> print(html)
    <!DOCTYPE html>
    <html lang="en">
    ...
  3. coolreader18 commented on Sep 27, 2021

    @coolreader18
    coolreader18
    on Sep 27, 2021
    Member
    More actions

    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.

  4. oroppas commented on Sep 27, 2021

    @oroppas
    oroppas
    on Sep 27, 2021
    More actions

    Could https://bugs.python.org/issue36011 be related?

    Reacted by Noa
  5. coolreader18 commented on Oct 3, 2021

    @coolreader18
    coolreader18
    on Oct 3, 2021
    Member
    More actions

    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?

  6. cn-kali-team commented on Oct 3, 2021

    @cn-kali-team
    cn-kali-team
    on Oct 3, 2021
    Author
    More actions

    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 sweat_smile

    Could you check if #3210 works?

    I recompiled the test and passed.
    It works. Thank you for your help.

    Reacted by Noa
  7. youknowone
    closed this as completedon Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.