I am trying to parse an RSS feed with feedparser. The below code snipped is cut-short for brevity
from google.appengine.api import urlfetch
import feedparser
print 'Content-Type: text/plain'
feed_url = 'http://parsethisurl'
feedinput = urlfetch.fetch(feed_url)
rss_parsed = feedparser.parse(feedinput.content)
......
#some logic here
.........
print "\n".join(episode_info) # printing out the desired output.
works fine on my python interpreter but when I add my application to gapp engine launcher and try to run it via localhost:10000 it gives me the following error
<type 'exceptions.ImportError'>: No module named feedparser
args = ('No module named feedparser',)
message = 'No module named feedparser'
feedparser module is already installed on my system.
>>> sys.version
'2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]'
>>> import feedparser
>>>
I read some articles on stackoveflow and blogs that feedparser doesn't work directly on gapp engine. I followed the advice and used urlfetch.fetch(feed_url) but than also I am getting an error.
PS: PythonPath on gapp launcher is C:\Python25\python.exe
You have feedparser installed locally, so when you run your application on development server it works. But in order to use feedparser on production you need to include it in your project, because GAE do not provide this library for you.
You need to upload feedparser along with your project files. For this you can copy it into your application root directory and then deploy your application.
Related
I followed the instructions and successfully installed pypostal python package (package to help parse addresses) https://github.com/openvenues/pypostal.
I'm trying to set this up so the python script can be callable through an apache server on an ubuntu box. It works fine when executing the script from Terminal. However, it doesn't work when I make a call to apache to execute the script and I get the following error in the apache logs. I believe it might be some pathing issue but I haven't had much luck to resolve it. Any ideas will be appreciated.
Error:
File "/var/www/html/cgi-bin/get_parsedAddress.py", line 5, in
from postal.parser import parse_address
ModuleNotFoundError: No module named 'postal'
python script contents:
import sys
from postal.parser import parse_address
addressList = parse_address(sys.argv[1])
print(addressList)
I'm using Python on my web server (which is Heliohost) and I'm unable to import some Python modules. Whenever I try to import them, I get a 500 internal server error.
The modules I'm not able to import are numpy and tensorflow, which should be installed because running the script below that should print all the installed modules
#!/usr/bin/python3.6
import cgitb
import pip
print("Content-Type: text/html")
cgitb.enable(format='text')
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
returns a lot of Python modules, with tensorflow and numpy as well.
Basically, the scripts work fine with any other Python module, it gives an error only with those two.
What could be the problem? Unfortunately, I can't access the server logs because my web server provider doesn't allow it, and with cgitb enabled (that should print any error in the code), it just returns the error 500 without printing anything else.
Here is the error I am receiving when I try to run my Google App Engine site locally. It actually works on my old computer (windows 10 and python 2.7.6 was installed) but not on a new one I just got with windows 10 and Python 2.7.11 installed. Any ideas on how to fix?
from _ssl import RAND_add, RAND_egd, RAND_status, SSL_ERROR_ZERO_RETURN, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE, SSL_ERROR_WANT_X509_LOOKUP, SSL_ERROR_SYSCALL, SSL_ERROR_SSL, SSL_ERROR_WANT_CONNECT, SSL_ERROR_EOF, SSL_ERROR_INVALID_ERROR_CODE
ImportError: cannot import name RAND_egd
You likely need to also install some OS-specific library, probably the local equivalent of ssl, see Using Runtime-Provided Libraries with the Local Development Server
This is using the Python SDK version 1.8.0.
My remote API works fine using remote_api_shell.py, but doesn't work when trying to accessing from within a python script. I'm using the sample code from google:
from google.appengine.ext.remote_api import remote_api_stub
import getpass
def auth_func():
return (raw_input('Username:'), getpass.getpass('Password:'))
remote_api_stub.ConfigureRemoteApi(None, '/_ah/remote_api', auth_func,
'localhost:8080')
and I'm also importing the fix_sys_path() from dev_appserver.py to set my sys.path correctly for the google app engine SDK:
import dev_appserver
dev_appserver.fix_sys_path()
that adds, among other paths, the following line to my sys.path:
'/google_appengine_1.8.0/lib/fancy_urllib'
However, the following error is thrown when the above call to remote_api_stub.ConfigureRemoteApi() is called:
opener.add_handler(fancy_urllib.FancyProxyHandler())
AttributeError: 'module' object has no attribute 'FancyProxyHandler'
Wait 7 years, and it all seems to work fine.
how can i import other external libraries in web2py? is it possible to
load up libs in the static file?
can somebody give me an example?
thanks
peter
If the library is shipped with python, then you can just use import as you would do in regular python script. You can place your import statements into your models, controllers and views, as well as your own python modules (stored in modules folder). For example, I often use traceback module to log stack traces in my controllers:
import traceback
def myaction():
try:
...
except Exception as exc:
logging.error(traceback.format_exc())
return dict(error=str(exc))
If the library is not shipped with python (for example, pyodbc), then you will have to install that library (using distutils or easy_install or pip) so that python can find it and run web2py from the source code: python web2py.py. Then you will be able to use regular import statement as described above. Before you do this make sure you installed the library properly: run python interpreter and type "import library_name". If you don't get any errors you are good to go.
If you have a third party python module or package, you can place it to modules folder and import it as shown below:
mymodule = local_import('module_name')
You can also force web2py to reload the module every time local_import is executed by setting reload option:
mymodule = local_import('module_name', reload=True)
See http://web2py.com/book/default/section/4/18?search=site-packages for more information.
In web2py you import external library as you normally do in Python
import module_name
or
from module_name import object_name
I am not sure what you mean by "in the static file"