nathank
nathank

Reputation: 23

Pycurl Error : AttributeError: 'module' object has no attribute 'Curl'

Brand new raspberry pi using the debian image from the pi site.

I used sudo apt-get install python-pycurl

My script looks like this

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()

I'm getting this

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'

Upvotes: 2

Views: 5300

Answers (2)

Cinder
Cinder

Reputation: 1609

python first checks in the current directory for a module, then in the python directory. rename your file to mypicurl.py or something. otherwise, you're just importing the script.

edit: i just saw your comment, and this means you havn't installed it properly. try a reinstall or install from a .deb

Upvotes: 0

BrenBarn
BrenBarn

Reputation: 251578

Look at the path in the traceback. It looks like you may be importing your own module called pycurl.py, not the actual pycurl library. Try renaming that file to something else so Python imports the real pycurl.

Upvotes: 3

Related Questions