fastly / fastly-py

A Fastly API client for Python
https://pypi.org/project/fastly/
MIT License
77 stars 59 forks source link

Module 'fastly' has no 'API' member #27

Closed Integralist closed 6 years ago

Integralist commented 8 years ago

Python Version

python --version
Python 2.7.11

PIP

pip install fastly

Reduced Test Case

import fastly

api_key = '123'

api = fastly.API()
api.authenticate_by_key(api_key)
print api.__dict__

I'm using the exact example from the README

Error

Module 'fastly' has no 'API' member
Integralist commented 8 years ago

There doesn't seem to be any good documentation around this library either?

By that I mean, we have the API docs, but it's unclear how to translate those calls into Python function calls exposed by this library (unless you expect developers to sift through the source code)

Any help, appreciated. Thanks.

thommahoney commented 8 years ago

@Integralist thanks for opening an Issue. Let me address each of the issues you've raised:

Module 'fastly' has no 'API' member

I am not able to reproduce this. Using the exact example in the README, I get a successful response from our API:

$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastly
>>> api = fastly.API()
>>> api.authenticate_by_key('MYKEY')
>>> api.purge_url('www.example.com', '/some/path')
True

Perhaps it's because you're using pip to install the package? In which case I am happy to solve the bug but I don't know how to begin troubleshooting it. The API class is defined here: https://github.com/fastly/fastly-py/blob/94184bfe3f024591a8723f26545d50cc6332197e/fastly/fastly.py#L11

unclear how to translate those calls into Python function calls

I completely agree. We will hopefully be addressing this concern in collaboration with our documentation team in the coming months.

At this time this python library supports a very small subset of our configuration API, but please let me know if you have a specific API call that you would like implemented (or can't determine if it is implemented).

Finally, I would point you to https://github.com/zebrafishlabs/fastly-python as a possible alternative to this library.

cmac4603 commented 8 years ago

I found I could get from fastly import fastly to work, maybe we are both using virtualenvs and/or pip? Couldn't find a httplib library though, is it python2 only? Gave up and looked elsewhere. Sorry.

cblkwell commented 7 years ago

I'm running into this same issue, trying to use python 3.5.1 in a virtualenv; I also installed via pip:

Python 3.5.1 (default, May  3 2016, 21:31:43) 
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastly
>>> conn = fastly.API()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'fastly' has no attribute 'API'
>>> from fastly import fastly
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nail/home/cblkwell/fastly-api-testing/lib/python3.5/site-packages/fastly/fastly.py", line 1, in <module>
    import httplib
ImportError: No module named 'httplib'
verkaufer commented 6 years ago

If you're running Python 3 it looks like the httplib class has been renamed http.client See: https://docs.python.org/2/library/httplib.html

psbanka commented 6 years ago

Fixed with v0.2.3