I can't seem to get the wsgiref module to work at all under Python 3.0. It works fine under 2.5 for me, however. Even when I try the example in the docs, it fails. It fails so hard that even if I have a print function above where I do: "from wsgiref.simple_server import make_server", it never gets printed for some reason. It doesn't thow any errors when run, and it just displays a blank page in the browser and doesn't log any sort of request.
Does anybody know what the problem may be? Thanks!
issue 4718:wsgiref package totally broken. sorry about that.
You're in uncharted territory with WSGI on Python 3.0 I'm afraid.
WEB-SIG knew long ago that wsgiref was broken going into 3.0, but chose to do nothing about it. The spec hasn't been updated to cope with 3.0; pushing WSGI forwards even for the things everyone pretty-much agrees on is just agonisingly slow. It's depressing and senseless.
So yeah, it's easy to fix the obvious error with header unpacking in simple_server, but you'll still be running on a server that has been converted from Python 2-to-3 automatically and not really tested, with no de-jure standard to say exactly what it should do... never mind framework compatibility.
Python 3.0 for web scripting: needs some work.
Related
I've got a bottle-based HTTP server that mostly shuffles JSON data around. When I run this in Python 2.7 it works perfectly, and in my route handlers I can access the JSON data via bottle.request.json. However, when I run it under Python 3.4 bottle.request.json is None.
I've examined the HTTP traffic, and in both cases it is exactly the same (as would expected since that's under control of the non-Python-dependent client.)
I also see that the JSON data is reaching bottle in both cases. If I print out bottle.request.params.keys(), I see the string-ified JSON as the only entry in the list in both cases. And the strings are identical in both cases. For some reason, however, the Python 2 version is recognizing the JSON data while the Python 3 version isn't.
Strangely, this used to work, but some recent change either in my code or bottle (or both) has broken things. Looking over my code, though, I can't see what I might have done to create the problem.
Does anyone know what's going on? Is this something I'm doing wrong at the client end, at the bottle configuration end, or is this a bottle defect? I searched for this problem both on google and the bottle issue tracker, but to no avail.
This turns out to have nothing to do with bottle. The ultimate cause of the problem is that the client request has two Content-Type headers due to a defect in an emacs lisp HTTP library. Embarrassingly, I've known about this defect for quite some time, but I thought I'd properly worked around it.
I'm not 100% sure why I see the variance between Python 2 and 3, but my guess right now is that it has to do with otherwise benign changes in the WSGI machinery between the versions.
I'm a beginner level user of Django and Python right now, and so far anything I do locally has immediately worked on my hosting once uploaded. My hosting is provided by Hostmonster.
However, I've just installed PyEnchant. All I use it for is basic spell checking and suggesting new words. Also, 'string' is always a string of words separated by '+'.
from enchant import Dict
def spellcheck(string):
spellcheck = Dict("en-GB")
suggestedword = []
for word in string.split('+'):
if len(word) > 2 and not spellcheck.check(word):
suggestedword.append(spellcheck.suggest(word)[0])
else:
suggestedword.append(word)
return suggestedword
Locally, using the Django dev server, all works fine. On my host I get:
Django Version: 1.4
Exception Type: MemoryError
Exception Location: /home/user/python/lib/python2.7/ctypes/__init__.py in _reset_cache, line 279
It seems to be throwing the error a few steps after 'from enchant import Dict'.
I'm guessing the dictionary is too large to store in temporary memory?
Any idea how to get around this? Please go easy on me if I'm either asking something very stupid, or in a very stupid way :).
If I'm leaving out any vital data, it's because I don't know it's important, so feel free to tell me what other information would help solve this (if it can be solved on a shared host).
Thanks in advance for any help!
EDIT1:
Using SSH, I can import and use PyEnchant:
>>> import enchant
>>> spellcheck = enchant.Dict("en-GB")
>>> spellcheck.suggest('nmae')
['name', 'mane']
Which makes me even more confused, as I have had no luck avoiding 'MemoryError' when I use it as above in my question.
EDIT2:
Still not able to figure this out. If I do 'import enchant' in any module, it seems to cause the MemoryError, yet I am able to use 'import enchant' via remote shell and the python interpreter.
EDIT3:
Still, after a few days of googling and trying things out, I can't get this MemoryError to go away. Has anyone seen this before with 'PyEnchant'? I'm thinking my host is perhaps not giving enough ram to load the PyEnchant import? Is there any way to change how memory is used by a module?
I have just had the same problem after moving my Django installation. The problem was httpd (Apache) access to the database. In my case it was Selinux but I assume that general UNIX type file permissions would cause a similar problem. In this instance it worked fine on the Django server but not on my local Apache when trying out a viable production setup.
Does your host use Linux?
Could you run Apache to help determine the problem?
the last couple of days I installed Python 2.7.3 and Neo4J community edition 1.8.M01. I managed to get the embedded python bindings to work, but as I need the py2neo REST bindings I've installed them like described at http://py2neo.org/. Moreover I can't download directly from git due to a "Permission denied (publickey)" error so I took the available py2neo-1.2.6.tar.gz version from the download section.
While the installation itself was not the problem, I can't get the example to work as on calling neo4j.GraphDatabaseService('http://localhost:7474/db/data') python crashes without any error message - Win7 64bit only pops up a message that the applicationn does not respond. Java, Python and Neo4J are all running on 64 bit basis and the server is accessible on http://localhost:7474. I even tried to force an output as described here: Catching a python app before it exits - but still no stacktrace or error-log.
I've installed everything from scratch or via the executables provided at www.lfd.uci.edu/~gohlke/pythonlibs/ several times now but nothing managed to get this example to work.
I have installed both tornado 2.2.1 and pycurl 7.23.1. pycurl.version_info() reveals: (3, '7.23.1', 464641, 'Windows', 28, 'OpenSSL/0.9.8s', 0, '1.2.5', ('gopher', 'http', 'https', 'imap', 'imaps', 'pop3', 'pop3s', 'rtsp', 'smtp', 'smtps'), None, 0, None) - moreover
c = pycurl.Curl()
c.setopt(c.URL, 'http://stackoverflow.com')
c.perform()
returns the content of the startpage.
I've followed the stacktrace via print-messages into tornado.IOLoop.start() and there into _run_callback() where it actually executes callback() and crashes. Not shure if the callback-function defined inside of tornado.HTTPClient.fetch() should be called here - printing the callback results in <tornado.stack_context._StackContextWrapper object at ...>
Any suggestion on how to fix this issue?
Thanks in advance,
Roman
edit: corrected port as of a typo
edit2: after a longer debug-session which narrowed the point of failure a bit, Nigel provided me with a way to deal with my issues by exchanging
self._http = http or httpclient.HTTPClient(curl_httpclient.CurlAsyncHTTPClient)
with
self._http = http or httpclient.HTTPClient()
in line 55 of rest.py. This is a workaround but does not solve the problem in the back of tornado/pycurl. The windows management console declares pycurl.pyd as the reason for the crash and as some of the nodes (after a seldom functioning intialization of the GraphDatabaseService) get stored within Neo4J and the Debug-Output below isn't shown anymore, the crash must occur between the send request and the return to the main application. I currently believe that either the Selection poll, which I fall back on Windows, is the reason for the crash or maybe the curl-handle gets shared between different threads - which should not happen (http://curl.haxx.se/libcurl/c/libcurl-tutorial.html) - and is somehow the most comprehensible reason imo
Sorry to hear that you're having issues with py2neo. I haven't carried out any testing under Windows since I only run Linux so I'm unsure whether there are any general incompatibilities there. I am also aware that error reporting is less than it should be which has been limited by the amount of time I've had to work on the project.
That said, I notice that you are running on port 4747 instead of the default 7474 - or this this a typo? Have you tried your short cURL test against the root database URI directly?
You seem to have covered all the bases looking at the layers involved so I'm unsure what else to look at here. I have considered adding an option to be able to switch between the curl_httpclient and the simple_httpclient - this may give an alternative to try. I will try to get something put up over the next few days.
Nige
I am a PHPer new to Python (2.7 on Win32) and I would like to know where Python is shoving any errors it finds?
Do I need to turn something on, if so where do I do that?
Or, is the idea that you develop using a shell and watch errors spat out via that?
Please share any other good Python debugging/sanity-saving mechanisms you wish you'd known about earlier - or if you have switched from PHP perhaps you can tell me what the Python equivalents of :
ini_set('error_reporting', 1);
display_errors();
trigger_error();
var_dump();
Try and Exceptions looks fairly similar.
I will probably stumble across these answers myself in time, but in the meantime this issue is bugging me (no pun intended).
Thanks a lot.
Python development is normally done in a shell, and you get a full traceback printed out on any uncaught exception.
If you want to log errors to file, have a look at the logging module. You can either catch exceptions directly, or override the sys.excepthook function which is called for an uncaught error. If you're using a framework for e.g. web development, it may have mechanisms to do this sort of thing already.
Is it possible to make python run on your homepage? I know, this is a really stupid question but please don't pick on me for my stupidity :)
If it is possible, how? Do you have to upload/install the executing part of Python to you website using FTP? or...?
Edit: Just found out my provider does not support python and that shell access is completely restricted. Problem solved :)
Everything depends on the hosting provider you use for your homepage -- do they offer Python among their services, and, if so, what version, and how do you write server-side scripts to use it (is it CGI-only, or...?) -- if not, or the version / deployment options disappoint, what do they allow in terms of giving you shell access and running long-time processes?
It's impossible for us to judge any of these aspects, because every single one of them depends on your hosting provider, and absolutely none of them depends on Python itself!-)
Yes, you can. I don't know exactly how but I know it is possible. Mabye look into this website:
https://trinket.io/
This website lets you do this. I sent them a message to see how they do it so I will update this to let you know after they respond.
Python is a scripting language, though it is used gracefully for building back end web applications.