Category Archives: Python

Python Error: pip install mysql-connector-python failed

Python pip install mysql-connector-python 2.0.1 failed

As shown in the figure:
Error display

Tried: pip install mysql-connector-python==2.0.1 The error remains

Solution:

wget https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.3.zip
unzip mysql-connector-python-2.0.3.zip
cd mysql-connector-python-2.0.3
python setup.py install

Reference: stackoverflow

[Solved] Python Image Library fails with message “decoder JPEG not available” – PIL

It is possible that the version of the pillow package is incorrect. Installing the latest one can solve the problem.

# install libjpeg-dev with apt
sudo apt-get install libjpeg-dev
# if you're on Ubuntu 14.04, also install this
sudo apt-get install libjpeg8-dev

# reinstall pillow
pip install --no-cache-dir -I pillow

Python Requests Error: Max retries exceeded with url

Use the requests library to request url, this error will occur, the reason is:

The server is overloaded, and no more links can be established. There are 4 possibilities:

  1. Too many http connections are not closed.
  2. The machine’s memory is insufficient.
  3. Another possibility is that the IP is blocked by the target website due to the high request frequency
  4. The requested URL address is wrong

Solution:

1. increase the number of retry connections
requests.adapters.DEFAULT_RETRIES = 5

2. close redundant connections
requests uses the urllib3 library, the default http connection is keep-alive, requests set False to close.
Operation method:
s = requests.session()
s.keep_alive = False

_ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

problem

In python 2.7.6 through the requests library, if you request an https address, an error will be reported:[Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

Error reminder: sslv3 handshake error

Solution

  • Method 1: Upgrade python to 2.7.10 to solve the problem
  • Method 2:pip install requests[security]

the reason

But these three libraries are missing: pyOpenSSL, ndg-httpsclient, pyasn1

reference

[Solved] Python2 Flask startup error: [Errno 10053]

First of all, this is not an exception of the Flask library. This error often appears in Python2.

The problem is: the problem with the SocketServer module in Python2.

Solution:

  1. Do not use the built-in Server, start the service through gunicoon or uwsgi
  2. runAdd in the method, threadedparameters:
app.run(threaded=True)
  1. Upgrade to Python3

How to Solve Python ImportError: cannot import name UnrewindableBodyError

Error message:

File "/usr/lib/python2.7/site-packages/urllib3/util/__init__.py", line 4, in <module>
    from .request import make_headers
  File "/usr/lib/python2.7/site-packages/urllib3/util/request.py", line 5, in <module>
    from ..exceptions import UnrewindableBodyError
ImportError: cannot import name UnrewindableBodyError

Solution, reloading urllib3library:

pip uninstall urllib3
pip install urllib3

There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)-skipping

The root cause of this problem first is that the requested target website no longer supports TLS versions 1.0 and 1.1.

  1. Pip install appear in the library when the solution: upgrade pip, command: curl https://bootstrap.pypa.io/get-pip.py | python. Note that because of the issue of the certificate authentication protocol version, it cannot be upgraded through the pip upgrade command. (The Python.org website has stopped supporting TLS versions 1.0 and 1.1)
  2. It occurs when an HTTPS request requests the library site, the solution: upgrade pyopenssl library, command: pip install -U pyopenssl.
  3. When creating a virtual environment, the pip version is still old, the solution:sudo pip install --upgrade pip virtualenv virtualenvwrapper

[Exception]’ascii’ codec can’t decode byte 0xe8 in position 2: ordinal not in range(128)

1. The cause of the abnormality

This is an error related to python

 Because by default, Python uses the ascii encoding method, and when Python converts between encoding methods, it will use unicode as the “intermediate encoding”, but the maximum unicode is only as long as 128, so here when trying to encode ascii characters When the string was converted into “intermediate code” unicode, the above error was reported because it exceeded its range.

 

Two, the solution

Add a sitecustomize.py file in the /usr/lib/python2.7/site-packages/ directory, the content is as follows:

import sys
sys.setdefaultencoding( ' utf-8 ' )

PIP Install Caused by SSLError(SSLError(1, ‘[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)’))

1. The problem

1.1 Problem interception

pip install redis -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, ‘[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)’))’: /simple/redis/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, ‘[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)’))’: /simple/redis/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, ‘[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)’))’: /simple/redis/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, ‘[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)’))’: /simple/redis/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, ‘[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)’))’: /simple/redis/
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/redis/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.tuna.tsinghua.edu.cn’, port=443): Max retries exceeded with url: /simple/redis/
(Caused by SSLError(SSLError(1, ‘[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)’))) – skipping
ERROR: Could not find a version that satisfies the requirement redis
ERROR: No matching distribution found for redis
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.tuna.tsinghua.edu.cn’, port=443): Max retries exceeded with url: /simple/pip/ (Cau
sed by SSLError(SSLError(1, ‘[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)’))) – skipping

1.2 Screenshot

2. The cause of the problem

Opened the packet capture tool

3. Problem solving

Just close the packet capture tool

[Solved] Cannot open .xlsx file, xlrd.biffh.XLRDError: Excel xlsx file; not supported

The reason is that xlrd has recently been updated to version 2.0.1 and only supports .xls files. So it x1 = xlrd.open_workbook("data.xlsx")will report an error.

You can install the old version of xlrd and run it in cmd:
it is recommended to uninstall the new version directly and download the old version of xlrd

pip uninstall xlrd
pip install xlrd==1.2.0

You can also use openpyxl instead of xlrd to open .xlsx files:

df=pandas.read_excel(‘data.xlsx’,engine=’openpyxl’)

If you are willing to be mediocre, please shoot yourself!