简体   繁体   中英

Apache, mod_wsgi, Django, and a Python user agent

I am having a problem with a user agent written in Python that I am now trying to use with a Bitnami Amazon Web Service that has Apache, mod_wsgi (for Python), and Django pre-installed. I am having a problem when trying to POST data to the Django site from the Python user agent.

For instance, when I assemble an URL with the following:

    rq = urllib2.Request('http://' + IP_ADDRESS + '/power/command/')
    r = urllib2.urlopen(rq)
    return r.read()

This GET is no problem. When I assemble an URL as follows, but try to POST data with it, like so:

        params = urlencode({'u': json.write(obj)})
        rq = urllib2.Request('http://' + IP_ADDRESS + '/power/command/update/', params)
        r = urllib2.urlopen(rq)
        ret_val = r.read()

I get a 404 error. If I simply remove the params from the Request constructor, I get a 500 error – which is more or less appropriate.

Both of these segments of code work just fine with the Django debug webserver('./manage.py runserver') that is part of Django. Any ideas on the problem, or even just how to debug are appreciated.

I have already tried to spoof the 'User-agent', but this doesn't seem likely since the GET works in the first instance. The Apache httpd.conf file seems pretty stock except for the mod_wsgi references. I had this working on a local development server at one time, but I can't seem to find the differences. I'm sure it's a configuration thing since the code works in the dev environment and with the debug server.

As a start, check your Apache access and error logs and see if you find something fishy over there:

How to debug errors?

Once Apache starts, it will create two log files, the access_log and the error_log / installdir /apache2/logs directory. You can change these files to see the exact error in the application.

from: http://wiki.bitnami.org/Components/Apache#How_to_debug_errors.3f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM