I am using the Python web.py framework to design a small web application.
As indicated in the tutorial, when working with authorization I tried the following in the
Python interpreter:
In [10]: import web
In [11]: from web.contrib.auth import DBAuth
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/home/local/user/python_webcode/<ipython console> in <module>()
ImportError: No module named auth
But I am getting the above error. Can anyone please let me know how to solve this error and explain why it is happening?
It looks like you do not have the auth module installed. I have assumed that the auth module you are trying to use the one at http://jpscaletti.com/webpy_auth/.
You've not indicated whether you installed web.py via easy_install or by running setup.py after downloading a tarball. In either case, I'd recommend that you:
Locate the web.py install folder
Download the auth module from the link above and extract the contents into the contrib/ folder of the web.py install folder
Related
I am trying to run my python scripts on my IIS website using CGI and I am having trouble with importing. When run on its own, the python scripts finds the mysql.connector module installed in my os perfectly fine, but when I try to run it on the website, it gives a Bad Gateway (502.2) error with the stacktrace stating ModuleNotFoundError: No module named 'mysql.connector'. I'm assuming CGI cannot find the module in my OS, how can I let it find the module? Do I have to specify my modules folder somewhere in the IIS like a PATH variable?
Here is the complete stacktrace of the bad gateway page:
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "Traceback (most recent call last): File "C:\Users\pedro\OneDrive\Documents\adet\ind.py", line 2, in import python_mysql File "C:\Users\pedro\OneDrive\Documents\adet\python_mysql.py", line 1, in import mysql.connector ModuleNotFoundError: No module named 'mysql.connector' ".
As a workaround, I simply copied and pasted all of my modules in my modules folder to my website's folder. I guessed that since my personal imports were working that it should also work if I added the other modules to the same folder and lo, it did. I hope there's a cleaner way to solve this, but for now I'll choose this as a solution.
I am trying to send data to the Azure Blob Storage and my first step was to just check the connection by using the sample code I found on the tutorial website:
from azure.storage.blob import BlockBlobService
blob_service = BlockBlobService(account_name, account_key)
blob_service.create_container(
'mycontainername',
public_access=PublicAccess.Blob
)
blob_service.create_blob_from_bytes(
'mycontainername',
'myblobname',
b'<center><h1>Hello World!</h1></center>',
content_settings=ContentSettings('text/html')
)
print(blob_service.make_blob_url('mycontainername', 'myblobname'))
Of course entered the account name and the account key. But I get this error, which I also get when using my own python script so this is a big problem for me:
Traceback (most recent call last):
File "azuretest.py", line 1, in <module>
from azure.storage.blob import BlockBlobService
ImportError: No module named 'azure'
I am a beginner in this topic and I am very lost. Can anyone tell me what to do? Thanks
Installing just the azure-storage library should be sufficient in stead of installing the entire SDK.
pip install azure-storage
Edit
I see you have already done this. The package might not be in your python path. You could try adding
import sys
sys.path.append('/usr/local/lib/python3.6/dist-packages')
at the top of your script (but I am not 100% sure that it will be there on your syste, it is on ubuntu)
or append it to your PYTHONPATH environment variable.
I have Google AppEngine SDK installed(at /usr/local/google-appengine), and the toy App can be launched and run with GoogleAppEngine Launcher with no issue.
However, I have some standalone scripts (testpbuf.py) in the app folder that I want to run with
$python testpbuf.py
then I got Python Import errors:
Traceback (most recent call last):
File "testpbuf.py", line 3, in <module>
from google.appengine.api import files
ImportError: No module named appengine.api
The script is trying to import AppEngine API and protorpc modules..
What's going one here? I have the SDK included in my PATH and I have no problem invoking from terminal. Any insights? Thanks a lot!
You need to get all the libraries inside the SDK added to your path. This can be done as follows:
import dev_appserver
dev_appserver.fix_sys_path()
Running code outside of the SDK web-server for things other than tests isn't likely to be that useful to you though ... when it runs on appengine, it has to be via WSGI.
I have written some basic Python code to try authenticate my credentials on twitter:
import twitter
api = twitter.Api(consumer_key='',
consumer_secret='',
access_token_key='',
access_token_secret='')
But I receive the following error message when doing so:
Traceback (most recent call last):
File "C:\Python33\nettest.py", line 3, in <module>
api = twitter.Api(consumer_key='',
AttributeError: 'module' object has no attribute 'Api'
Can anyone see what I am doing wrong? I have tried variations on this code but they all seem to fall down with the api part of the twitter 1.14.2 that i am using. i have installed this module via pip 3.3 to my python 3.3 directory. when i look in lib>site_packages>twitter i can see that there is a module installed called api. I'm really not sure what is going wrong as this should seemingly be a simple piece of code to run.
Any ideas?
simply uninstall twitter sudo pip uninstall twitter
Now install python-twiiter sudo pip install python-twitter... and it works..
If you were using the python-twitter You have a local file named twitter.py Rename it to twitterhelper.py or some other name and it should fix your problem. This was what fixed it for me.
Save your python file with any name other than twitter.py.
import twitter
api = twitter.Api(consumer_key=' ',
consumer_secret=' ',
access_token_key=' ',
access_token_secret=' ')
friends=api.PostUpdate("First Tweet from PYTHON APP ")
I have done everything as said at http://abhi74k.wordpress.com/2010/12/21/tweeting-from-python/ but when I full inside it and press enter, nothing happens. Can you help me about that?
Ok it is because of that I couldn't download python-twitter API correctly. It gives me this error when I try to follow those steps:
figen#figen-Satellite-A350:~/Downloads/python-twitter-0.8.2$ python setup.py install
running install
running build
running build_py
running install_lib
copying build/lib.linux-x86_64-2.7/twitter.py -> /usr/local/lib/python2.7/dist-packages
error: /usr/local/lib/python2.7/dist-packages/twitter.py: Permission denied
http://code.google.com/p/python-twitter/
Ok I installed setup.py but now it gives this error:
figen#figen-Satellite-A350:~/Downloads/python-twitter-0.8.2$ python twitter_test.py
Traceback (most recent call last):
File "twitter_test.py", line 29, in <module>
import twitter
File "/home/figen/Downloads/python-twitter-0.8.2/twitter.py", line 65, in <module>
import oauth2 as oauth
ImportError: No module named oauth2
Now it says twitter module doesn't have the module. How to get it?
api = twitter.Api(consumer_key='removed',
consumer_secret='removed',
access_token_key='removed',
access_token_secret='removed')
friends=api.PostUpdate("If you see this,I managed to send my first tweet from Python Shell. Yay! =)")
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
api = twitter.Api(consumer_key='removed for security=)',
AttributeError: 'module' object has no attribute 'Api'
There are several things causing your problem.
1) The permission denied error (error: /usr/local/lib/python2.7/dist-packages/twitter.py: Permission denied) is because you do not have administrator privileges. Try sudo python setup.py install
2) You need to install the missing dependencies (i.e. oauth2) you can get oauth2 from here http://github.com/simplegeo/python-oauth2 make sure you have the other dependencies needed which are SimpleJson and HTTPLib2. You can find more details on this information on the python-twitter-api site.
Hope this solves it!
You need to install twitter which include Api . http://code.google.com/p/python-twitter/downloads/detail?name=python-twitter-0.8.2.tar.gz this version contain Api .