qpython-android / qpython

QPython is an Android Python engine primarily designed for Python and AI learners. It offers a range of impressive features to enhance Python programming experience.
https://www.qpython.org
1.03k stars 191 forks source link

"requests" problem with QPython3 - urlopen chunked #179

Closed Kpyt closed 4 years ago

Kpyt commented 5 years ago

Hi All,

I use Qpython3 on Android 9 Nokia 6.1. I have installed the "requests" module: pip3 install requests The following script works fine on linux, but fails on QPython3:

** import requests from bs4 import BeautifulSoup

URL = 'https://ubuntu.com' headers = {"User-Agent": 'Mozilla/5.0 (Linux; Android 9; Nokia 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.111 Mobile Safari/537.36'} page = requests.get(URL, headers=headers)

soup = BeautifulSoup(page.content, 'html.parser') **

It gives errors as follows:

/data/user/0/org.qpython.qpy3/files/bin/qpython3-android5.sh /storage/emulated/0/qpython/scripts3/bos.py && exit

/emulated/0/qpython/scripts3/bos.py && exit
Traceback (most recent call last): File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/urllib3/connectionpool.py", line 603, in urlopen chunked=chunked) File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/urllib3/connectionpool.py", line 344, in _make_request self._validate_conn(conn) File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn conn.connect() File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/urllib3/connection.py", line 370, in connect sslcontext=context) File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/urllib3/util/ssl.py", line 355, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/ssl.py", line 407, in wrap_socket File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/ssl.py", line 814, in init File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/ssl.py", line 1068, in do_handshake File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/ssl.py", line 689, in do_handshake ssl.SSLError: [SSL: NO_CIPHERS_AVAILABLE] no ciphers available (_ssl.c:841)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/requests/adapters.py", line 449, in send timeout=timeout File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/urllib3/connectionpool.py", line 641, in urlopen _stacktrace=sys.exc_info()[2]) File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/urllib3/util/retry.py", line 399, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='ubuntu.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: NO_CIPHERS_AVAILABLE] no ciphers available (_ssl.c:841)'),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/storage/emulated/0/qpython/scripts3/bos.py", line 6, in page = requests.get(URL, headers=headers) File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/requests/api.py", line 75, in get return request('get', url, params=params, kwargs) File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, kwargs) File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/requests/sessions.py", line 533, in request resp = self.send(prep, send_kwargs) File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/requests/sessions.py", line 646, in send r = adapter.send(request, kwargs) File "/data/user/0/org.qpython.qpy3/files/lib/python3.6/site-packages/requests/adapters.py", line 514, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='ubuntu.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: NO_CIPHERS_AVAILABLE] no ciphers available (_ssl.c:841)'),)) 1|:/ $

Kpyt commented 5 years ago

I did further investigation. The above code works fine with "Pydroid 3", which uses the following versions of python and requestes:

Python 3.7.2 (default, Mar 20 2019, 15:02:54) [GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__ 
'2.22.0'

while qpython 3:

qpy3/files/bin/qpython3-android5.sh && exit
Python 3.6.6 (qpyc:3.6.6, Jul 26 2018, 03:54:22) [BUILD WITH QPY3-TOOLCHAIN (https://github.com/qpython-android) ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.22.0'

The qpython has problem with "https" protocol. The following code works fine on qpython 3:

import requests
from bs4 import BeautifulSoup

url = "http://www.google.com"

page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')

print(soup)

When we change the url to "https://www.google.com", it fails again.

riverfor commented 4 years ago

Can you try this temporary solution please ? https://github.com/qpython-android/qpython3/issues/61