Tag Archives: Python script error

[Solved] Linux OS python Script Error: smtplib has no attribute SMTP_SSL

foreword

After configuring the linux server environment, run the python script and find that the smtplib module reports an error, but not on windows, the error is as follows:

linux  module 'smtplib' has no attribute 'SMTP_SSL'

configure

  • Centos7
  • Python3.7

reason

Find the source code of smtplib.SMTP_SSL and find that the SMTP_SSL class is only established when have_ssl is True, and the have_ssl variable requires ssl dependency to be True, then the problem is found, there is no ssl dependency on linux

solution

  • Install ssl dependencies
yum install openssl openssl-devel
  • Verify that the installation was successful, check the version
openssl version -a
  • Enter your python3.7 directory, for example, my python-3.7.6.tgz file is decompressed and placed in the /usr/tgz/python/Python-3.7.6 directory, enter the Modules folder under the file, some versions is the Module file
cd /usr/tgz/python/Python-3.7.6
cd Modules
  • Modify the Setup file, the changes are as follows, and uncomment the 5 lines of code at more than 200 lines
vim Setup

Press ESC, :wq, Enter and save and exit

  • Return to the previous directory, that is, the python3.7 directory, and reinstall python
cd ..
make && make install
  • Run the code, problem solved

How to Solve Python AttributeError: ‘module’ object has no attribute ‘xxx’

Python script error attributeerror: ‘module’ object has no attribute ‘xxx’ solution

when you encounter a few problems, you should pay attention to the same problem when you don’t ask for a solution

1. When naming py script, it should not be the same as the reserved word and module name of Python
(it is not easy to notice when naming files)
2 Delete the. PyC file of the library (because the. PyC file will be generated every time the PY script runs; if the. PyC file has been generated, if the code is not updated, the runtime will still go PyC, so you need to delete the. PyC file), rerun the code, or find an environment where you can run the code and copy and replace the. PyC file of the current machine Import questions </ font> </ font>