【Python】TypeError: an integer is required (got type str)

tags: Python

Problems encountered in debugging code today

TypeError: an integer is required (got type str)

problem causes

In the open function of the open file object in python3, the following is the wrong way of writing

 read_helper=open(checkpath,"r","utf-8")

For the third parameter, encoding="utf-8" must be added to specify the encoding method

read_helper=open(checkpath,"r",encoding="utf-8")

If encoding= is not added, the interpreter assumes that the third parameter is the specified buffering, and this variable itself needs to be passed in an integer variable.

def open(file, mode='r', buffering=None, encoding=None, errors=None, newline=None, closefd=True):

For the binary reading mode, the encoding method cannot be formulated, and the correct writing method is as follows

read_helper=open(checkpath,"rb")

Intelligent Recommendation

Pyspark: TypeError: An Integer is Required (got type bytes) resolved

Linux [Ubuntu, other versions are for reference only] Run the Pyspark program in Jupyter Notebook error, query information discovery, current2020.11.18Pyspark still does not support higher version of ...

python: Use PyInstaller packaged into exe files, and TypeError: an integer is required (got type bytes) exception resolution

python: Use PyInstaller packaged into exe files, and TypeError: an integer is required (got type bytes) exception resolution 2019-11-12 15:50:22 lad. Read the article tag number 225: python package ex...

Python: Use PyInstaller to package into an exe file, and TypeError: an integer is required (got type bytes) exception resolution

Using Python 3.6 or above to use pyinstaller for packaging will result in a TypeError: an integer is required (got type bytes) exception. The solution and installation pyinstaller tutorial are as foll...

[Question] Python packaging EXE error: typeerror: an inTeger is required (got type bytes)

Pack Python files into an exe command: pyinstaller -f -w xxx.pyWhen the results are compiled, an error is not generated without generating an EXE file. solve PyInstaller -F -w .\xxx.pySuccessfully gen...

Python uses Pyinstaller package exe file error: TypeError: an INTEGER IS Required (Got Type Bytes)

Python packs into an EXE file First, you need to install the Pyinstaller library, then enter the target file directory, enter the command line package PY file, but an error occurred:TypeError: an inte...

More Recommendation

The Python program generates a Windows executable / command window does not display / Can not generate exe error TypeError: an integer is required (got type bytes) Solution

Use pyinstaller Installation command: pip install pyinstaller or pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz The second recommended: because I just started using the ...

TypeError_ an integer is required (got type tuple) RandomResizedCrop

TypeError: an integer is required (got type tuple) RandomResizedCrop Labels (space separated):pytorch This error may be caused by the version, but I did not find a solution on the Internet, and I foun...

DeprecationWarning: an integer is required (got type float).

There is a sample code in the first section of Chapter 12 of "Python Programming" published by Tsinghua University Press, [Example 12-1] Display the hello world on the graphical interface (S...

TypeError:an integer is required (got type tuple)

The PyTorch version in the experimental environment is 0.4.1, and the Torchvision version is 0.2.1. (This version looks familiar, is it cooked?) Error: Because there is a mistake in errorstorch.transf...

TypeError: an integer is required (got type bytes) error correction method of seeking correction

TypeError: an integer is required (got type bytes) error correction method of seeking correction Traceback (most recent call last): File “F:/python/automatic/tsTserv.py”, line 18, in tcpCl...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top