Tag Archives: Python

Error reporting in Firefox using selenium in Python

python error in Firefox with selenium:

Traceback (most recent call last):
File “G:\python_work\chapter11\test_selenium_firefox.py”, line 10, in <module>
driver = webdriver.Firefox()
File “C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py”, line 154, in __init__
keep_alive=True)
File “C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 140, in __init__
self.start_session(desired_capabilities, browser_profile)
File “C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 229, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File “C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 297, in execute
self.error_handler.check_response(response)
File “C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities

=============================

python version 3.4.3 , selenium version 3.4.3 , Firefox version 49.0.

 

The reason for the error is the version compatibility between python, selenium, Firefox , after upgrading Firefox to the latest version 55.0 the problem is solved.

Also selenium needs geckodriver when calling Firefox, download it and add it to the Firefox installation directory, and add the Firefox installation directory to the system environment variable Path.

=============================

Test code:

1 from selenium import webdriver
2 
3 driver = webdriver.Firefox()
4 driver.get("http://www.google.com")

[Solved] Error when Python reads a file Unicode decodeerror

python read files error: UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 205: illegal multibyte sequence

python read file warning: “UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 205: illegal multibyte sequence”

Solution 1:

FILE_OBJECT= open('data.txt','r', encoding='UTF-8')

Solution 2:

FILE_OBJECT= open('data.txt','rb')

 

[Solved] Python installation error: One or more issues caused the setup to fail.

After python 3.7.3 is installed, clicking on the exe starts an error

One or more issues caused the setup to fail. Please fix the issues and then retry setup. For more information see the log file.

Windows 7 Service Pack 1 and all applicable updates are required to install Python 3.6.4(64-bit).

Please update your machine and then restart the installation.

Reason.

Windows system problem, because the version is too old, need to need to install the SP1 package upgrade package

Click on the link above and select the red mark to download, the download will be completed and you are good to go.

 

Python upgrade resulted in an error using yum

Today, we plan to install walle 2.0 according to the official documents http://www.walle-web.io/docs/index.html Step by step

At this step, an error is suddenly reported

yum install -y mariadb-devel gcc gcc-c++ python-devel

 

At first, I wondered if there was a problem with the yum source. Download and load the alicloud source again

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo 
yum clean all  
yum makecache

If you can’t find it, you still report an error

check the python version

# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53) 

It is found that Python has been upgraded to 2.7.5, and the python version required by Yum is 2.6, resulting in an error

modify the yum startup file prefix

# cat /usr/bin/yum
#!/usr/bin/python2.7

It is found that it is useless and there is no backup. Python is directly updated to 2.7.5. The library used by Yum cannot be loaded and the module cannot be loaded

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

Please install a package which provides this module, or
verify that the module is installed correctly.

 

Find the information, try to install another version of python2.6.6, and modify the yum startup file, but the module cannot be loaded

reinstall Python and Yum

1. Uninstall existing Python and force the removal of installed programs and their associations

rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps

Force deletion of all residual files

whereis python |xargs rm -frv

2. Uninstall existing yum

rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps

Force deletion of all residual files

whereis yum |xargs rm -frv

3. Download the RPM package corresponding to the version

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-build-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-build-libs-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-libs-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-sign-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-python-4.11.3-35.el7.x86_64.rpm

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-devel-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-libs-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-virtualenv-15.1.0-2.el7.noarch.rpm

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-aliases-1.1.31-50.el7.noarch.rpm

Install these packages after downloading (- – force forced installation)

rpm -Uvh --force --nodeps --replacepkgs *.rpm

After installing these RPM packages, yum can be used normally. If you still report the following, it means that you haven’t downloaded all the RPM packages

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   /usr/lib64/python2.7/site-packages/rpm/_rpm.so: undefined symbol: rpmpkgVerifySi

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

 

Then press the walle official document to install step by step, and the installation is completed successfully ~:)

say important things three times

Python upgrade is upgraded with the downloaded package. Back up the old version before upgrading

Python upgrade is upgraded with the downloaded package. Back up the old version before upgrading

Python upgrade is upgraded with the downloaded package. Back up the old version before upgrading

 

Error in Python compilation on MAC no module named mysqldb

Compile error for python on Mac: No module named MySQLdb

You installed python

You did brew install mysql

You did export PATH=$PATH:/usr/local/mysql/bin

And finally, you did pip install MySQL-Python

appear:

Collecting mysql-python
Downloading MySQL-python-1.2.5.zip (108kB)
100% |████████████████████████████████| 112kB 324kB/s
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File “<string>”, line 1, in <module>
File “/private/tmp/pip-build-fwrZHD/mysql-python/setup.py”, line 17, in <module>
metadata, options = get_config()
File “setup_posix.py”, line 43, in get_config
libs = mysql_config(“libs_r”)
File “setup_posix.py”, line 25, in mysql_config
raise EnvironmentError(“%s not found” % (mysql_config.path,))
EnvironmentError: mysql_config not found

Solution:

Reinstall MYSQL

 

Python uses xlwt length limit to report errors

Python uses xlwt to report an error string longer than 32767 characters

The xlwt module is used to write xlsx files in the project. Today, we encountered the error of string longer than 32767 characters. Through consulting the data, we found that excel cells support 32767 characters at most. Finally, we got two solutions xlsxwriter and openpyxl

At first, I used openpyxl to write Excel files. I found that if there are some special characters in the cell content, an openpyxl.utils.exceptions.illegalcharactererror error error will be thrown. I used pandas.to_Excel also throws the same error, indicating pandas.to_Excel also uses the openpyxl method by default. If special characters can be controlled manually, they can be processed by themselves. If not, they have to use the xlsxwriter method

Xlsxwriter is similar to xlwt. It truncates when the cell character size exceeds 32767, so no error will be reported

Solutions to Python Chinese annotation errors

I recently started learning Python and found that once there are Chinese comments in the code, errors will be reported

Cause

If there are non ASCII characters in the file, you need to specify the encoding Declaration on the first or second line

Solution

Add such a sentence in the first or second line
# — Coding: UTF-8–

Perfect solution

Solutions to Python Chinese annotation errors

Once there are Chinese comments in the code, an error will be reported

Cause

If there are non ASCII characters in the file, you need to specify the encoding Declaration on the first or second line

Solution

Add such a sentence in the first or second line
# — Coding: UTF-8–

Perfect solution

[Solved] Python Connet MYSQL Error: MySQL dB_exceptions.OperationalError: (2059, < NULL>).

When Python connects to MySQL data:
an error message will prompt MySQL dB_exceptions.OperationalError: (2059, < NULL>)。

Python package:

mysqlclient

Analysis reason:
mysql8.0 provides a new authentication encryption method, caching_sha2_Password, it is recommended to update to the latest connector and client. However, it also provides another option, that is, to use the encryption method MySQL of the previous version_native_password。 One of the solutions to mysqlexceptions.operationalerror: (2059, null):

Solution
modify the password and use MySQL instead_native_Password encryption method. After flush privileges

 

Python:IndentationError: expected an indented block

sum = 0
for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
sum = sum + x
print(sum)

The code is as above, but an error is reported during operation:

 

It is found that the indentation is missing, and it is corrected as follows:

sum = 0
for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
    sum = sum + x
print(sum)

No problem

Run as:

  However, if the code format is corrected:

sum = 0
for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
    sum = sum + x
    print(sum)

Output is:

It can be seen here that the most distinctive feature of Python is to write modules with indentation

The number of indented whitespace is variable, but all code block statements must contain the same number of indented whitespace, which must be strictly enforced

indentationerror: indent does not match any outer indentation level the error indicates that the indenting methods you use are inconsistent. Some are tab indenting and some are space indenting. Just change to consistent

If so  IndentationError: unexpected indent   If there is an error, the python compiler is telling you “Hi, man, the format in your file is wrong. It may be that the tab and space are not aligned”. All Python have very strict format requirements

Therefore, the same number of line indentation spaces must be used in Python code blocks

It is recommended that you use at each indentation level   single tab   or   two spaces   or   four spaces  , Remember not to mix

Indenting the same set of statements constitutes a code block, which we call a code group

For compound statements such as if, while, def and class, the first line starts with a keyword and ends with a colon (:), and one or more lines of code after this line form a code group

We call the first line and the following code group a clause

So the last two runs with different indents have different results. Because the indentation is different, the code block is different