Tag Archives: Python

Error in installing Python package — readtimeouterror

1、 Problem: error readtimeouterror is reported when installing Python package — read time out

2. Solutions
there are three methods: one is to switch the download source; Second, download the installation package of the corresponding platform and install it; Third, download the source code, compile and install
  The first method is to switch the download source recommendation

      https://pypi.tuna.tsinghua.edu.cn/simple

      http://pypi.douban.com/simple/

      Example: PIP install   Package name   — user -i   https://pypi.tuna.tsinghua.edu.cn/simple

      Permanent switch: under Linux, modify or create ~ /. PIP/pip.conf. The modification contents are as follows:

   [ global]

    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

  Under windows, directly create a PIP directory in the user directory, such as C: \ users \ XX \ pip, and create a new file pip.ini, as follows:

  [ global]

    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

 

  The second method is to download the installation package of the corresponding platform

      Baidu finds the PY package, selects the package of the corresponding platform, downloads and installs it, as shown in the figure below

 

 

 

 

The third method is to download the source code, compile and install

      If the installation package of the corresponding platform cannot be found, you can only download and compile the source code and then install it. For example, the last zip file in the figure below is the source code

 

 

 

 

python TypeError: an integer is required

Problem Description:

When using socket locally to transfer data to NetAssist, it is found that Python error typeerror: an integer is required error is reported after executing Python file

code:

  1 #!/usr/bin/env python3
  2 from socket import *
  3 udpSocket = socket(AF_INET, SOCK_DGRAM)
  4 destIp = input('enter ip:')
  5 destPort = input('enter port:')
  6 destData = input('enter data:')
  7 
  8 udpSocket.sendto(destData.encode('gb2312'),(destIp, destPort))

execution result:

enter ip:192.168.162.1
enter port:8080
enter data:haha
Traceback (most recent call last):
  File "udp-code.py", line 8, in <module>
    udpSocket.sendto(destData.encode('gb2312'),(destIp, destPort))
TypeError: an integer is required (got type str)

cause:

After querying the python document, it is found that the parameters passed do not meet the requirements of the socket. SendTo () method

Document Description:

s.sendto (string [, flag], address)
send UDP data. Send data to the socket. Address is a tuple in the form of (IPADDR, port) and specifies the remote address. The return value is the number of bytes sent
destport should be of type int

modify code:

  1 #!/usr/bin/env python3
  2 from socket import *
  3 udpSocket = socket(AF_INET, SOCK_DGRAM)
  4 destIp = input('enter ip:')
  5 destPort = int(input('enter port:'))
  6 destData = input('enter data:')
  7 
  8 udpSocket.sendto(destData.encode('gb2312'),(destIp, destPort))

result:

Summary:

After an error is reported, analyze the cause of the error according to the information

Query relevant documents and whether the parameter format meets the requirements

[Solved] Python hashlib MD5 Error: TypeError: Unicode-objects must be encoded before hashing

1.error message: TypeError: Unicode-objects must be encoded before hashing

2.error message: TypeError: object supporting the buffer API required

The correct way to write it should be

codes:

import hashlib
def md5pwd(password):
m = hashlib.md5()
m.update(password)
mpwd = m.hexdigest()
return mpwd
print(md5pwd(b’123456′))

 

The problem of error reporting when importing openpyxl from Python has finally been solved

Problem: after tossing all morning, openpyxl has been installed and uninstalled many times. The CMD clearly shows that the installation is successful, but an error is reported when the python file is imported

1. After installing openpyxl, the python file import has been reporting errors. After a morning’s efforts, I finally found the correct solution on the Internet

2. After installing openpyxl, you need to add components to pycharm. The steps are as follows

    Help—> In findaction, enter the project interpreter and open the project interpreter

3. Click the “+” sign on the right

 

 

 

4. Enter the available packages interface, enter openpyxl in the input box, and click Install Package below. Later, you will be prompted with “package ‘openpyxl’ install successfully” below

 

5. At this time, if you import openpyxl in Python, you will not report an error

 ( Note: when other packages report errors (such as pandas), import them in DOS Python environment first. If no errors are reported; Then repeat the above steps in pycharm — project interpreter and install the corresponding package.)

Python learning notes – Import utils error

Today, I encountered a problem with Keng father. I searched for the reason for it for a long time and finally solved it. I specially record it here

Running environment: Windows eclipse

I configured the running environment of Python in eclipse and wrote Python code in eclipse

Operation steps:

1. On the python interactive command line, enter import utils without error

2. In the pydev project of eclipse, enter import utils, and the error is: unresolved import: utils

Solution:

1. In eclipse, click window preferences pydev interpreters Jython   Interpreter, in libraries, click new folder and add the path – > Click “OK”

2. Restart eclipse to solve the problem

Similarly, it can be solved as follows:

1. Right click project to open the menu – > Select properties – > Select “pydev interpreter/grammar” – > Click the link “click here to configure an interpreter not listed.” – > In the “libraries” tab, click “new folder” to add the path of utils – > Click “OK”

2. Restart eclipse

 

In this way, you can solve the problem of “unresolved import” in eclipse pydev