python使用pymysql連線資料引起的錯誤

2021-09-29 05:57:35 字數 1018 閱讀 6570

報錯1:

file "d:\program files\python36\lib\site-packages\pymysql\connections.py", line 325, in __init__

self.connect()

file "d:\program files\python36\lib\site-packages\pymysql\connections.py", line 589, in connect

self.host_info = "socket %s:%d" % (self.host, self.port)

typeerror: %d format: a number is required, not str

報錯原因:

資料庫連線時port的資料型別錯誤,**配置型別為str,要求的資料型別為int

報錯2:

file "f:/python/auto_test_plat_demo/apitest/apiauto_testcase2.py", line 19, in test_readsqlcase

charset = 'utf-8'

file "d:\program files\python36\lib\site-packages\pymysql\__init__.py", line 94, in connect

return connection(*args, **kwargs)

file "d:\program files\python36\lib\site-packages\pymysql\connections.py", line 283, in __init__

self.encoding = charset_by_name(self.charset).encoding

attributeerror: 'nonetype' object has no attribute 'encoding'

報錯原因:

資料庫連線引數編碼型別錯誤,修改編碼型別為utf8

Python使用pymysql鏈結mysql資料庫

先安裝pymysql如下圖 author pythontab.com 可有可無 匯入pymysql的包 import pymysql try 獲取乙個資料庫連線,注意如果是utf 8型別的,需要制定資料庫 conn pymysql.connect host localhost user root p...

Python使用PyMySQL連線MySQL資料庫

目錄 環境要求 安裝 示例mysql 版本 因為我們本地安裝python的時候,一般都會安裝好pip工具,所以我們可以直接使用pip命令安裝pymysql 如果不會安裝python的朋友們可以看下我的安裝python文章 pip install pymysql出現以下提示就表示安裝成功了 windo...

python使用pymysql把資料寫入mysql

簡單粗暴直接上 import pymysql import requests from lxml import etree def connect 連線本地資料庫 db pymysql.connect host localhost user root password bbqbbq database...