python

Python authentication

Hi, I want to be able to authenticate to a website and then access some of the private pages in that site. I've looked at some examples and tutorials but I can't get it to work. For example, I want to access https://www.billmonk.com/home which is available only after authentication. Here's the code I'm using: url = 'https://www.billmo...

lambda calling @classmethod fails

Maybe I get this completely wrong but I ran into some odd issues with lambda calling @classmethod. I have the following class: class MyClass: LAMBDA = lambda: MyClass.ClassMethod() @classmethod def ClassMethod(cls): pass But this fails whenever LAMBDA is called with: TypeError: unbound method <lambda>() must be called wit...

Problems regarding Boost::Python and Boost::Threads.

Me and a friend are developing an application which uses Boost::Python. I have defined an interface in C++ (well a pure virtual class), exposed through Boost::Python to the users, who have to inherit from it and create a class, which the application takes and uses for some callback mechanism. Everything that far goes pretty well. Now, t...

urllib2 connection timed out error

I am trying to open a page using urllib2 but i keep getting connection timed out errors. The line which i am using is: f = urllib2.urlopen(url) exact error is: URLError: <urlopen error [Errno 110] Connection timed out> ...

csrf error in django

Hello, I want to realize a login for my site. I basically copied and pasted the following bits from the Django Book together. However I still get an error (CSRF verification failed. Request aborted.), when submitting my registration form. Can somebody tell my what raised this error and how to fix it? Here is my code: views.py: # Crea...

How to use list comprehension to add an element to copies of a dictionary?

given: template = {'a': 'b', 'c': 'd'} add = ['e', 'f'] k = 'z' I want to use list comprehension to generate [{'a': 'b', 'c': 'd', 'z': 'e'}, {'a': 'b', 'c': 'd', 'z': 'f'}] I know I can do this: out = [] for v in add: t = template.copy() t[k] = v out.append(t) but it is a little verbose and has no advantage over what I'm...

Outlook PST File Parsing in Python

Is there a library available in Python we can use to parse and read an outlook pst file? ...

NetworkX library add nodes to gml

I have a .gml file with some data. I want to append new entries into the same gml file by the networkx graph library. Somehow I land up over-writing them. ...

Redirecting stdio from a command in os.system() in python

Usually I can change stdout in python by changing the value of sys.stdout. However, this only seems to affect print statements. So, is there any way I can suppress the output (to the console), of a program that is run via the os.system() command in python? Thank you ...

Integrity Error in Sqlite Database

I am trying to import large amounts of data into a sqlite DB through python 2.5. The data consists of strings, but there are multiple duplicates in the data. An example; addres,type_code, location 123,01,work 123,01,mall 132,49,home 132,33,home My issue is that when loading the data I get an Integrity error, address and type_code are...

How valid is pep-8 " Limit all lines to a maximum of 79 characters."

This seems like such a relic from the past in age of 25" monitors. I am looking for what stackoverflow members think about this, and do you always honor this recommendation. ...

PyQt4 and pyuic4

I'm trying to compile my first .ui file using PyQt4 on a mac with osx 10.6. I'm getting a syntax error and I'm not sure what it means. >>> import sys >>> sys.path.append('/Users/womble/Dropbox/scratch/') >>> from PyQt4 import QtCore, QtGui >>> pyuic4 Urb.ui > Urb.py File "<stdin>", line 1 pyuic4 Urb.ui > Urb.py ^ Synt...

Regular expression to search for a string1 that is never followed by string2

How to construct a regular expression search pattern to find string1 that is not followed by string2 (immediately or not)? For for instance, if string1="MAN" and string2="PN", example search results would be: "M": Not found "MA": Not found "MAN": Found "BLAH_MAN_BLEH": Found "MAN_PN": Not found "BLAH_MAN_BLEH_PN": Not found "BLAH_MAN_B...

does google-app-engine has "required_admin" method..

@required_admin def get(self): i want to use this method to make user must be admin. thanks ...

Adding methods to a simple RPC server in a clean and separated way

Hello: I created a simple RPC server to perform certain tasks common to our teams, but which are called from different networks. The server looks like this (I don't include error handling for brevity): from twisted.internet.protocol import Protocol, Factory from twisted.internet import reactor import json class MyProtocol(Protocol): ...

Django Admin Templating

Hi, I am learning django and building my own project. I want to change the admin section to my own interface, I have added sub-directory to the templates names "admin".And started change the base.html The problems are- I want to add my own css file, how I can do it?My css file is located on my MEDIA_ROOT directory.How I can do that? ...

Python socket server craps out after receiving data

I'm currently dabbling in sockets. I've got a jquery script that uses a very small flash swf file to establish a true socket connection. As a server I'd like to use python. Everything works, but I can only send information to the server just once. I've tried 2 pieces of python code for the server. I guess since they both have the same ...

Return an image to the browser in python, cgi-bin

I'm trying to set up a python script in cgi-bin that simply returns a header with content-type: image/png and returns the image. I've tried opening the image and returning it with print f.read() but that isn't working. EDIT: the code I'm trying to use is: print "Content-type: image/png\n\n" with open("/home/user/tmp/image.png", "r") a...

Implementing a SAML client in Python

Hi, I'd like to integrate a web site written in Python (using Pylons) with an existing SAML based authentication service. From reading about SAML, I believe that the IdP (which already exists in this scenario) will send an XML document (via browser post) to the Service Provider (which I am implementing). The Service Provider will need...

Cross-compiling python extensions under Linux using distutils

Hello, everybody! Is there any way to compile both Windows and Linux versions of Python/distutils/SWIG/C++ extensions under Linux? As far as I understand the problem is at least in obtaining windows version of python-dev. Thank you. ...