I have a simple mashup CGI program written in Python (2.6) that, among other sources, should grab the summary of Wikipedia articles to present to the user along with results from several other sources (as it is what mashups are supposed to do). Unfortunately I have no access to the console on the remote server and therefore I cannot install any modules using pip, easy_install, etc. Following the suggestion from here, I have been able to use BeautifulSoup4. However, I had no success when attempting to use the same strategy (unpacking the source directory and uploading it the cgi-bin directory in the remote server) with the wikipedia and requests modules.
Here is the test script I am using:
#!/usr/bin/python
import cgitb
cgitb.enable()
import urllib
import urllib2
from bs4 import BeautifulSoup
#import requests
#import wikipedia
print "Content-type: text/html\n\n"
print "<html><head><title>CGI Demo</title></head>"
print "<h1>Hello World</h1>"
print "</html>"
If I enable the lines that import the requests and wikipedia modules, I get the dreadful "500 Internal Server Error", otherwise the script runs OK.
So, my question is, is it possible to use the wikipedia and requests modules (in fact, wikipedia depends upon requests) without installing them in the usual ways?
Thanks in advance for any hints or suggestions.
Related
This question was asked before but never answered well:
I need beautifulsoup4 to scrape through a websites HTML and get information. I want to use that information in my Alexa-skill.
How do I import/use bs4 in my Alexa developer console?
I've already read how to make a deployment package (https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html), but I don't understand how to download/zip bs4.
I am new to Python, AWS and Alexa developer console, so I am sorry if that question is very easy to answer.
I tried to create a ziped folder named lamda and upload it under upload code, but running my skill wuth import bs4 just errors
I need to create a webpage (HTML) and when I clic on a button, text input from a user is used in a python script and it is executed on the server side ?
I'd like to know how other new libraries can be imported on the server in order for the script to be executed. I use libraries such as Spacy or sklearn which i had to install them on my python us
PS : I'm using WordPress
Thank you for reading me ^^
EDIT 1
It looks like I can import the sqlite3 package. Now I'm working on figuring out how to specify the IP address of the hosted server so I can connect to it. It's not looking likely though.
EDIT 2
It looks like sqlite3 is not designed to access hosted databases. The search continues.
This is a pretty basic question, however I haven't found any resources on Namecheap's website, here, or through Google searches that shed any light on my problem. I'm trying to write a python script that will query my hosted database to retrieve records. So far I haven't gotten past the first step of importing a module and this is my code:
#!/usr/bin/python
print "Content-type: text/html\n\n"
import cgitb
cgitb.enable()
import PyMySQL
cgitb works fine and prints out the following error message:
I also tried importing MySQLdb and received the same error. Does anyone have experience with databases, python, and namecheap?
I'm trying to fetch a page using python requests with this code in views.py:
s = requests.Session()
r = s.get("https://www.23andme.com/")
I get the error Exceeded 30 redirects. My app is a Google App Engine Django app. I've gotten this code to work in the python console and a django server on pythonanywhere.com, but for some reason it isn't working on google app engine. What could be causing this? Thanks
Edit: It seems like there is another issue with the Requests module in my app. I have this code to add an email to a mailchimp list:
m = mailchimp.Mailchimp(MAILCHIMP_API_KEY)
list_response = m.lists.list()
but if fails with the error HTTPS/SSL is required
Try installing urllib3 (and other stuff, see below).
See, historically there were tons of issues for requests with google app engine (and see issue #498). Those were mostly resolved with urllib3 support for GAE that came with v1.3. It came out a long time ago (the current release is 1.7), so its probably not the issue, however when you initially install requests, it includes urllib3 in a folder called packages and maybe it doesn't include the entirey of it.
I also tried searching the source code for requests and found this interesting:
# Attempt to enable urllib3's SNI support, if possible
try:
from requests.packages.urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()
except ImportError:
pass
Going deeper, the contrib package includes a pyopenssl.py script which requires:
SSL with SNI-support for Python 2.
This needs the following packages installed:
pyOpenSSL (tested with 0.13)
ndg-httpsclient (tested with 0.3.2)
pyasn1 (tested with 0.1.6)
So, to sum up:
Install urllib3 and other SSL packages mentioned above, then try running that request you're doing again and see if anything has changed. My guess is that this will (at the very least) help with the mailchimp as it's also complaining about SSL/HTTPS issues.
If that doesn't work, try using urllib3 api instead of requests to do the same task and see if that's working. If so, the problem is specifically with the packaged urllib3 that requests is using, which might need some patching.
import urllib3
http = urllib3.PoolManager()
r = http.request('GET', 'https://www.23andme.com/')
Sorry this isn't a definite solution, hopefully one of my suggestions will help. Update me as to the progress I'll try and help out as much as I can
According to this discussion, the issue is with netrc on Google App Engine. I was able to work around the problem by using an older version of Requests (1.2.3 in my case, but others may work too.)
Edit: According to this answer, Requests 2.1.0 should work as well.
Using CGI scripts, I can run single Python files on my server and then use their output on my website.
However, I have a more complicated program on my computer that I would like to run on the server. It involves several modules I have written myself, and the SQLITE3 module built in Python. The program involves reading from a .db file and then using that data.
Once I run my main Python executable from a browser, I get a "500: Internal server error" error.
I just wanted to know whether I need to change something in the permission settings or something for Python files to be allowed to import other Python files, or to read from a .db file.
I appreciate any guidance, and sorry if I'm unclear about anything I'm new to this site and coding in general.
FOLLOW UP: So, as I understand, there isn't anything inherently wrong with importing Python files on a server?
I suggest you look in the log of your server to find out what caused the 500 error.
You can get an extensive error message by adding the following lines at the beginning of your CGI script:
import cgitb
cgitb.enable()