windows - 用python3的pymysql库连接mysql时出现AttributeError
PHP中文网
PHP中文网 2017-04-18 10:11:56
0
1
649

刚开始学用python整合mysql,代码如下

import pymysql

conn = pymysql.connect(host='127.0.0.1',unix_socket='/tmp/mysql.sock',user='zzp',password='zaqwsx123',db='mysql')
cur = conn.cursor()
cur.execute('USE scraping')
cur.execute('SELECT * FORM pages WHERE id = 1')
print(cur.fetchone())
cur.close()
conn.close()
  • 运行时就出错了:

    Traceback (most recent call last):
    File "C:/Users/zzp/PycharmProjects/untitled2/test.py", line 3, in <module>
    conn = pymysql.connect(host='127.0.0.1',unix_socket='/tmp/mysql.sock',user='zzp',password='zhangzhipeng123',db='mysql')
    File "C:UserszzpAppDataLocalProgramsPythonPython35-32libsite-packagespymysql__init__.py", line 90, in Connect
    return Connection(args, *kwargs)
    File "C:UserszzpAppDataLocalProgramsPythonPython35-32libsite-packagespymysqlconnections.py", line 688, in init
    self.connect()
    File "C:UserszzpAppDataLocalProgramsPythonPython35-32libsite-packagespymysqlconnections.py", line 881, in connect
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    AttributeError: module 'socket' has no attribute 'AF_UNIX'

百度时有人说删除socket.pyc文件,但我没找到什么socket.pyc文件
有人说是命名冲突。但具体的解决办法是什么呢?

PHP中文网
PHP中文网

认证高级PHP讲师

membalas semua(1)
Peter_Zhu

Melihat mesej ralat anda, saya tahu bahawa persekitaran yang anda jalankan ialah tingkap, tetapi sambungan yang ditulis dalam kod py anda ialah kaedah sambungan pelayan Linux, dan ia juga merupakan sambungan soket

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan