AJAX Post requests

2009-02-09 Thread PJ
Hi,
I have a simple web server using  BaseHTTPServer, and the def do_POST
(self) function works fine for regular forms that are submitted to it,
but when I send an AJAX POST to it it does nothing (I've tried to just
get it to print to check it's nothing else but it doesn't even do
that, although it does for a regular POST request.
The post function is
def do_POST(self):
global rootnode
try:
ctype, pdict = cgi.parse_header(self.headers.getheader
('content-type'))
if ctype == 'multipart/form-data':
query=cgi.parse_multipart(self.rfile, pdict)
self.send_response(301)

self.end_headers()
print(query.get('data'))
print('test')
h = codecs.open ("log.txt", "a", encoding="utf8")
h.write("test")
h.close()


except :

 pass

The AJAX post is appearing in the command prompt as any other post and
I can't see any reason why it shouldn't go to this function,
particularly if it works for a regular (non-AJAX) post, so any help
would be appreciated,
Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: setuptools, accessing ressource files

2009-10-03 Thread PJ Eby
On Oct 2, 7:04 am, Patrick Sabin  wrote:
> I use setuptools to create a package. In this package I included some
> images and I checked that they are in the egg-file. The problem is how
> can I access the images in the package?
>
> I tried pkgutil.get_data, but only got an IOError, because the EGG-INFO
> directory doesn't exist.
>
> I tried
> pkg_resources.get_distribution('dist').get_metadata('images/image.png')
> with a similar error (IOError)
>
> What is the best way to access images distributed in an egg file?

The resource_stream(), resource_string(), or resource_filename()
functions:

http://peak.telecommunity.com/DevCenter/PkgResources#basic-resource-access

>
> -Patrick

-- 
http://mail.python.org/mailman/listinfo/python-list