2

使用来自 pi 站点的 debian 映像的全新树莓派。

我用 sudo apt-get install python-pycurl

我的脚本看起来像这样

import pycurl
c = pycurl.Curl()
c.setopt(c.POST, 1)
c.setopt(c.SSL_VERIFYPEER, 1)
c.setopt(c.CAINFO, '/etc/ssl/certs/ca-certificates.crt')
c.setopt(c.URL, 'https://theurl.com')
c.setopt(c.USERPWD, 'user:pass')
c.setopt(c.POSTFIELDS, 'Field1=This&Field2=That')
c.perform()

我得到这个

Traceback (most recent call last):
  File "pycurl.py", line 1, in <module>
import pycurl
  File "/home/pi/test/pycurl.py", line 3, in <module>
    c = pycurl.Curl()
AttributeError: 'module' object has no attribute 'Curl'
4

2 回答 2

3

查看回溯中的路径。看起来您可能正在导入自己的名为 的模块pycurl.py,而不是实际的 pycurl 库。尝试将该文件重命名为其他文件,以便 Python 导入真正的 pycurl。

于 2012-08-22T17:15:10.150 回答
0

python首先在当前目录中检查一个模块,然后在python目录中。将您的文件重命名为mypicurl.py或其他内容。否则,您只是在导入脚本。

编辑:我刚刚看到你的评论,这意味着你没有正确安装它。尝试重新安装或从 .deb 安装

于 2012-08-22T17:23:22.807 回答