New to Python, WxPython etc, etc
I am totally new to Python and WxPython and need to write an
application which can open up an external windows from a plug-in within
GAIM (using pyGAIM). I have managed to hack some code together from
what little I have covered so far, however GAIM refuses to open until I
have closed the extra window. I appreciate this is probably a simple
point but I would be grateful for any advice people can offer on how I
can make them both appear so that people can interact with either GAIM
and/or the contents of the window. I am using Python 2.3.5, and GAIM 2
(beta).
I have attached the hacked code below which is based on a merging some
samples from WxPython and pyGaim. I have tried moving the bit below to
within def plug_in load but to no avail.
"app = MyApp(0)
app.MainLoop()"
Thanks in advance,
Rod
import _gaim
import wx
from wxPython.wx import *
ID_ABOUT = 101
ID_EXIT = 102
class MyFrame(wxFrame):
def __init__(self, parent, ID, title):
wxFrame.__init__(self, parent, ID, title,
wxDefaultPosition, wxSize(200, 150))
self.CreateStatusBar()
self.SetStatusText("This is the statusbar")
menu = wxMenu()
menu.Append(ID_ABOUT, "&About",
"More information about this program")
menu.AppendSeparator()
menu.Append(ID_EXIT, "E&xit", "Terminate the program")
menuBar = wxMenuBar()
menuBar.Append(menu, "&File");
self.SetMenuBar(menuBar)
EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.TimeToQuit)
def OnAbout(self, event):
dlg = wxMessageDialog(self, "This sample program shows off\n"
"frames, menus, statusbars, and this\n"
"message dialog.",
"About Me", wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def TimeToQuit(self, event):
self.Close(true)
class MyApp(wxApp):
def OnInit(self):
frame = MyFrame(NULL, -1, "Hello from wxPython")
frame.Show(true)
self.SetTopWindow(frame)
return true
PLUGIN_INFO = {
'python_api_version' : 2,
'name' : "A Simple Test Plug-in",
'version' : "0.3",
'summary' : "This simply does nothing",
'description' : "Cheese",
'author' : "[EMAIL PROTECTED]",
'url' : "http://www.xxx.com/";,
'load' : "plugin_load",
'unload' : "plugin_unload"
}
def timeout0(anObject):
print 'py:timeout0',anObject
return False
def timeout1(anObject):
print 'py:timeout1',anObject
##return True
return False
def signed_on_cb1(data,account,conv,msgText):
print 'p2:signed_on_cb1'
print 'Data',data
print 'account',account
print 'conversation',conv
print 'msgText',msgText
print 'account.gc',account.gc
blist = gaim.gaim_get_blist()
print blist.root
print conv.name,conv.title,conv.history
buddy = gaim.gaim_find_buddy(account,conv.name)
print buddy,buddy.name,buddy.alias
group = gaim.gaim_find_buddys_group(buddy)
print group,group.name,group.totalsize
return {'r':True,'a3':'this is my text:'+msgText}
def menu_item_activate_cb(node,data):
pass
def blist_node_extended_menu_cb(data,node,menu):
print 'node',node
print 'menu',menu
## if (!GAIM_BLIST_NODE_IS_BUDDY(node))
## return;
## buddy = (GaimBuddy *)node;
##act = gaim.gaim_blist_node_action_new("Send message",
## menu_item_activate_cb,None)
##print act
##*menu = g_list_append(*menu,act);
def plugin_load(plugin):
print 'py:plugin_load'
accs = gaim.gaim_accounts_get_all()
print accs
for account in accs:
print account
if account:
print account.username,account.alias
print 'New:',gaim._GaimAccount()
gaim.gaim_python_timeout_add(plugin,2000,timeout0,"this is timeout
0")
gaim.gaim_python_timeout_add(plugin,1000,timeout1,"this is timeout
1")
handle = gaim.gaim_conversations_get_handle()
gaim.gaim_python_signal_connect(plugin,handle,"writing-im-msg",
signed_on_cb1,"abc")
gaim.gaim_python_signal_connect(plugin,gaim.gaim_blist_get_handle(),
"blist-node-extended-menu",
blist_node_extended_menu_cb,None);
print 'py:after plugin load'
def plugin_unload(plugin):
print 'py:plugin_unload'
app = MyApp(0)
app.MainLoop()
--
http://mail.python.org/mailman/listinfo/python-list
Visualisation Engine for Python
I am looking for a 2D data visualisation or graphics library for Python. Can anyone point me in the right direction? Thanks in advance, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Visualisation Engine for Python
Thanks for all the help everyone. rod -- http://mail.python.org/mailman/listinfo/python-list
Sockets on Windows and Mac
I am new to Python and have been writing some socket based programmes on Windows (with some success), however I am unable to get them to work on Mac. Are there differences in the way the socket module works on Windows and Mac? I would appreciate any simple code samples people my have for creating a very basic server on Macpython, I have copied code from various tutorials but as yet they don't appear to work. Thanks, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Sockets on Windows and Mac
Hi Peter, I am currently importing the socket library when I write the programs, I have had no problems with it on my PC at work, but the Mac at home steadfastly refuses to work. As for existing libraries, I am new to Python so am kean to avoid re-inventing the wheel :-) Cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Sockets on Windows and Mac
I am on 10.3, I keep getting exceptions when it hits lines like mySocket.bind (SERVER_IP, 2727 ) or mySocket = socket.socket(socket.AF_NET,socket.SOCK_STREAM) The code I am using is copied from a tutorial on a website somewhere. Cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Sockets on Windows and Mac
Hi Peter, I am currently importing the socket library when I write the programs, I have had no problems with it on my PC at work, but the Mac at home steadfastly refuses to work. As for existing libraries, I am new to Python so am kean to avoid re-inventing the wheel :-) Cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
Python and Word
Is there a way to write Word plug-ins in Python? I am using Python 2.3.5 and Word 2000, and need to be able to write a small network application with a basic GUI which can run inside Word. cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Word
Hi Tim, Thanks for replying. It needs to be a small application/plug-in which can visualise data that is either within Word already or which is sent to it via a server on the localhost. The actual GUI will be very simple, for example and image and some buttons. What it actually has to do should be quite simple, but I have never programmed Word plug-ins before, and am also new to Python. cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Word
Hi Tim. Thanks for the tips. As for VBA, well I am looking at that as well. Although for architectural reasons elsewhere in the project Python or C++ are the only options. While I could use several languages I am trying where possible to stick to one or at most two. cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
CORBA: Fnorb Problems
Hi, I have installed Fnorb and everything seems to have gone ok. However I keep getting the error message below. This is despite the fact that the MS CL c++ preprocessor seems to be in PATH. I can type "cl" and although I get nothing back in the DOS window, there is also no error message. Traceback (most recent call last): File "C:\Python24\Lib\site-packages\Fnorb\script\cpp.py", line 53, in -toplevel- raise "No C/C++ pre-processor found in your PATH!" No C/C++ pre-processor found in your PATH! On seeing what information is returned the variables which are searching for the presence of CL in PATH come back with nothing. System: Windows XP, Python 2.4, Most recent version of Fnorb 1.3. Any pointers are welcome. Thanks in advance. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: CORBA: Fnorb Problems
> > I used omniorb, and have been very satisfied with it. You might consider > switching. > > Diez Thanks, I have just downloaded that plus omniORBpy as well. I have the binary version of omniORB but need to build omniORBpy, from what I can see the build process is aimed at GCC and not VC++. Anyway I will try to figure it out. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: CORBA: Fnorb Problems
> > > > Traceback (most recent call last): > > File "C:\Python24\Lib\site-packages\Fnorb\script\cpp.py", line 53, in > > -toplevel- > > raise "No C/C++ pre-processor found in your PATH!" > > No C/C++ pre-processor found in your PATH! > > You don't say *when* this error occurs, i.e. what is the command that > returns the exception. Assuming it's when you try to compile an IDL file > with fnidl, just try: > fnidl --internal-cpp ... Sorry you are right I did not say, but you guessed correctly. However even when I try your advice I still receive the same error. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: CORBA: Fnorb Problems
Thanks the fix you provided me with workds perfectly. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python for me?
[EMAIL PROTECTED] wrote: > By large I mean an application with intensive operations, such as a > fancy GUI maybe a couple of threads, accessing a database, etc. I am still fairly new to Python, I only started using it at the start of this year and then stopped for a while. However the project I undertook at the start of the year built a system using the technologies above, in addition it used SVG graphics, Jabber Instant messaging and the windows API. All of these were built within threads and used a client/server architecture. I have also built some small wxPython based GUI's. Overall I found Python ideal for the task, both in terms of development time and reliability - although my knowledge of the Windows API was not what it should have been (I mainly used Linux/Mac OS X user) so I experienced a few problems. Also there was a lack of good online docs about Python based Windows API calls. You can interface to a few databases very easily including MySQL and SQLite. I have been using the latter recently for my task and it works very well. Also I have found that using Stackless Python drastically improves the reliability of thread based applications. Also performance "can" be substantially improved by using the Psyco library, although I have know it to make things worse. Overall my experience of Python was very positive and this was in no small part due to the help I received from people here. I hope this helps. Best, Rod -- http://mail.python.org/mailman/listinfo/python-list
USB support
Hi, I need to write a program which can access the USB ports on Mac and Linux, is there a library available for Python? Thanks in advance. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: USB support
Thanks for this, I have managed to build PyUSB and install it in the relevant directory. However I get bus errors when I try the PlugUSB.py example. Does anyone know why this is likely to be the case? I am using Macpython 2.4, Libusb 0.1.12 and PyUSB 0.3.3 on an Intel based mac. Thanks in advance. Rod Tim Roberts wrote: > "rodmc" <[EMAIL PROTECTED]> wrote: > > > >I need to write a program which can access the USB ports on Mac and > >Linux, is there a library available for Python? > > The "stable" version of Libusb includes a Python binding. The version in > development does not yet. > -- > - Tim Roberts, [EMAIL PROTECTED] > Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: USB support
Thanks, well if what you say is true then it would make sense. Cheers, rod Tim Roberts wrote: > "rodmc" <[EMAIL PROTECTED]> wrote: > > > >Thanks for this, I have managed to build PyUSB and install it in the > >relevant directory. However I get bus errors when I try the PlugUSB.py > >example. Does anyone know why this is likely to be the case? > > > >I am using Macpython 2.4, Libusb 0.1.12 and PyUSB 0.3.3 on an Intel > >based mac. > > It is my understanding that OS/X does not support the /proc filesystem. > Without /proc, libusb cannot operate. > -- > - Tim Roberts, [EMAIL PROTECTED] > Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Help req: Problems with MySQLdb
I have written an application that connects to a database on a remote machine which uses MySQLdb 1.2.0. The application works perfectly when connecting to the database from a remote machine, however when it attempts to connect to a database on the same machine a connection error is generated. I have attached what little info I can below. DBSERVERIP = "1.2.3.4" db = MySQLdb.connect(host=DBSERVERIP, user="user", passwd="password", db="nuke") --- it refuses to connect on the above line and the exception is caught and a message displayed. I have tried changing the server IP to "localhost" or the hostname, however the same problem arises. Information: Python 2.3.5, MySQLdb 1.2.0, MySQL 5.0.21 and Windows 2K pro. I would be grateful for any help with this problem. Kind regards, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Help req: Problems with MySQLdb
Hi, Thanks for your email. Well I am kind of new to exceptions in Python, but here is the code used below, as you can see it is somewhat basic. Is there a way to display more information about the exception? Best, rod try: #Exception handler for database queries db = MySQLdb.connect(host=DBSERVERIP, user="user", passwd="password", db="nuke") except: print "A database connection error has occurred" return False else: #The rest of the program Sybren Stuvel wrote: > rodmc enlightened us with: > > --- it refuses to connect on the above line and the exception is > > caught and a message displayed. > > So why do you think this exception and the error message contain > no useful information at all? > > Sybren > -- > The problem with the world is stupidity. Not saying there should be a > capital punishment for stupidity, but why don't we just take the > safety labels off of everything and let the problem solve itself? > Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Python and Prolog
Can anyone recommend a library which will let me bridge between Python and Prolog? I have looked around but as yet have had no luck. Either the libraries are no longer being updated or the links do not work. FYI: I am using Python 2.4 and SWI Prolog, I would also like to make sure it can run on Mac, Linux and Windows - the latter being my main development machine. Thanks in advance for any help. Kind regards, rod -- http://mail.python.org/mailman/listinfo/python-list
Python and CORBA
Can anyone recommend an easy to install COBRA implementation which works with Python? I am using Windows XP. Thanks in advance. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and CORBA
Thanks to everyone for their help. I had tried OmniORB and while the base library worked ok, the Python bit OmniORBpy seems to dislike working... Perhaps there is something wrong with my settings. I will also try the Python only suggestion. cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
Python and Flash
Can anyone provide me with advice on how easy (or otherwise) it is to drive a Flash animation (stored locally but displaed in a browser) with a Python application. Basically information is getting streamed to a Python client and this is expected to update the Flash animation. It sounds odd, but it has to be done. Thanks, Rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Flash
Thanks for the help so far. There are two Python applications involved, one runs on a remote PC (server) and another on the users PC (client). The server at present merely receives and sends out messages via an instant messaging platform. Based on the information it receives via the IM platform it then updates the Flash application. I guess it could do it in a number of ways, one method being to send messages to the Flash application to update the display, or another to update the visualisation on the server then get the web browser (on the client PC) to reload it. Thanks, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGTK
Well I have just started using Python and have found wxPython to be pretty good, it is built upon the WxWindows framework.It is also cross-platform. You can find it at www.wxpython.org. It appears to be easy to understand and there are a few GUI builder tools around for it as well. Rod -- http://mail.python.org/mailman/listinfo/python-list
Curios issues with Editors
I recently wrote a program in IDLE and it runs perfectly. However when the same application is executed within SPE I receive errors saying that certain socket items are not callable, in particular AF_INET. I am new to Python, is there a reason why somethings will run in IDLE and not SPE? I could post the source code but it is changing quite a bit, so this is more of a general question than one about a specific bug or issue. Best, Rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Curios issues with Editors
As I said I am most likely to have made an error, being a newbie and all that. Here is the offending function. I said i would not post source code but there you go... As I said I plan to change this function, so it will no doubt be out of date quite soon. def senddata(msg): host = "localhost" port = 21568 buf = 1024 addr = (host,port) UDPSock = socket(AF_INET,SOCK_DGRAM) UDPSock.sendto(msg,addr) UDPSock.close() cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
Embedding an Application in a Web browser
Is it possible to embed a Python application within Internet explorer? If so how do people recommend going about it. As for the application it has to be able display simple animated graphics such as circles, lines and squares. However if someone clicks on a shape it should open up another application, such as Word. Thanks, Rod Python Newbie -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding an Application in a Web browser
Thanks for all the comments. I will elaborate slightly to give everyone an idea of what is going on. Basically I need to create a dynamic visualisation which sits in the active desktop, basically behind the desktop icons and in front of the windows wallpaper. Windows lets you define a web page which can be displayed in this way. The application itself can sit on the local users computer, rather than actually being downloaded via the web. It will be retrieving data from a variety of sources. If there is another way to do it then that would be good, for example writing another active desktop application which people can use. The user has to be able to resize, move or get rid of the visualisation if they wish to do so. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
MySQL
I need to write a Python application which connects to a MySQL 5.0 database. Can anyone point me in the right direction or a compatible library? Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQL
Hi Wolfram, Thanks for the tip, after some server issues I am pleased to say the library appears to work perfectly with MySQL 5. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
email libraries and threads
Hi, I am writing a threaded application, part of which relies on sending messages to users. However I cannot get the smtplib and some other email related libraries to work inside threads (they work ok when not in threads). Is there a problem with using threads and email? If so is there a solution available or any tips which people can give me? Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Strange Threads Behaviour...
I have written an application which uses threads and the XMPP library - this is a library which supports the jabber instant messaging protocol. The application works fine when run from Idle, however I get thread errors when I try to run it as an EXE created with Py2Exe or when it is run within other editors such as SPE. I need to ship the application to end users so any pointers on thread handling when creating shipping apps would be useful. For reasons of confidentiality I cannot post all the source code, however the error log is below. Thanks in advance. Best, rod update (server adddress deleted) Jabber Login Successful Greg forced SASL not to be used. Auhentication fails if it is used. Warning: unable to perform SASL auth os (serger address deleted). Old authentication method used! idname: glocopex executing Exception in thread Thread-1 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 442, in __bootstrap File "I:\My Documents\pyscripts\Newclient\newclient.py", line 368, in run File "I:\My Documents\pyscripts\Newclient\newclient.py", line 404, in GoOn File "I:\My Documents\pyscripts\Newclient\newclient.py", line 399, in StepOn File "C:\Python23\lib\site-packages\xmpp\dispatcher.py", line 116, in Process File "C:\Python23\lib\site-packages\xmpp\transports.py", line 101, in receive Script terminated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange Threads Behaviour...
Hi Diez, No this occurs when the client is executed. Basically it runs as you see above then terminates. It should be noted that the errors involving the /xmpp libraries seem to change each time. I have no doubt it is connected to that, but the error does not happen at all when I run the client through IDLE. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Creating an Active Desktop Window
Hi, Does anyone know how I can create an Active Desktop window from within a Python script? It would also be good to know how to refresh that window and nothing else. At present I have an application which writes to a file which is read by the Active Desktop (embeded IE), then a refresh command is issued which refreshes the whole screen. This is a bit clumsy and also the user needs to manually set up the Active Desktop component. I have been looking around for some solutions to this and as of today my book on PyWin32 has still not arrived. Thanks in advance for any pointers. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Strange Memory Leaks
I have written an application which seems to work fine most of the time and takes up about 26k when run. However when the PC (Windows 2k) is put to sleep/locked and the application is left to run it starts eating up memory, indeed about 400mb was the recent record. Is there any automated way of finding out where the memory leak is arising? Or a method of suspending the application when the screen is locked and/or the PC goes to sleep? Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Win32: Detecting when system is locked or sleeping
I have written an application which works perfectly when the machine is operating under normal conditions, however when the screen becomes locked it imediately starts to fill up several hundred MB's of memory. Is there a way to detect when the system is locked? Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32: Detecting when system is locked or sleeping
Yes, I mean just a good old fashioned screen lock (for security) initiated by the user. 'Sadly' there has been nothing as exciting as a blue-screen of death as yet, not even when the app swells to 400MB. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32: Detecting when system is locked or sleeping
Further to my last post, I will try some of the tips presented above. Also the app writes to the screen display (or Active Desktop). As someone suggested, that could be where the problem is. Best. rod -- http://mail.python.org/mailman/listinfo/python-list
Multi form CGI examples?
Hi, I have been looking online for some examples of how to create multi form CGI scripts using Python. I have come across a few but am still a little confused - being new to CGI on Python. Can anyone provide me with some pointers to useful tutorials or advice on the best way to go about it? I think I have mastered the basic elements of parsing and processing single forms so it is really a matter of architecture and examples more than anything else. For example should I write everything in one file or split it up over several, also should I use HTML files or hard code the HTML in the script? As for the actual forms, there will probably be three of them. Each will have some elements which are required. Other aspects include the ability to upload files and check whether the person is logged in (probably via cookies although the people who operate the site have yet to get back to me). These are all kind of newbie questions when it comes to CGI, but not being a web developer tips and advice are appreciated. I would rather avoid costly mistakes! Thanks in advance. Kind regards, rod -- http://mail.python.org/mailman/listinfo/python-list
Server side cookie problems
Hi, I am trying to set a cookie on a client computer using the Cookie
module however all I get is the text being printed in the browser
window. Can anyone point me in the right direction so that the cookie
data is set without it appearing in the browser? A shortened version
of the code is below, in the full version there is also userID check,
this seems to work ok. I have removed that portion for the time being
as its the writing part that is the problem.
import sys, os, string, cgi, Cookie, urllib2
from types import ListType
cookie = Cookie.SimpleCookie()
cookieHdr = os.environ.get("HTTP_COOKIE", "")
cookie.load(cookieHdr)
def writetocookie(number):
#writes the ID of the database entry to a cookie
cookie["dataid"]=number
print "Content-Type: text/html"
print
print "Set-Cookie: dataid=",cookie["dataid"].value
writetocookie(1)
I presume this is not the correct way to write a cookie, the examples
I have found online don't seem to provide much more information.
Kind regards,
rod
--
http://mail.python.org/mailman/listinfo/python-list
Re: Server side cookie problems
On Feb 6, 8:00 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 06 Feb 2008 15:27:53 -0200, rodmc <[EMAIL PROTECTED]> > escribi�: > > > Hi, I am trying to set a cookie on a client computer using the Cookie > > module however all I get is the text being printed in the browser > > window. Can anyone point me in the right direction so that the cookie > > > def writetocookie(number): > > #writes the ID of the database entry to a cookie > > cookie["dataid"]=number > > print "Content-Type: text/html" > > print > > print "Set-Cookie: dataid=",cookie["dataid"].value > > > I presume this is not the correct way to write a cookie, the examples > > I have found online don't seem to provide much more information. > > I don't know either if this is the right way, but surely the Set-Cookie > header must appear *before* the blank line; that blank line separates the > headers from the response body. > > -- > Gabriel Genellina Thanks, that seemed to work. rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Server side cookie problems
On Feb 7, 1:06 pm, rodmc <[EMAIL PROTECTED]> wrote: > On Feb 6, 8:00 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > > > > > En Wed, 06 Feb 2008 15:27:53 -0200, rodmc <[EMAIL PROTECTED]> > > escribi�: > > > > Hi, I am trying to set a cookie on a client computer using the Cookie > > > module however all I get is the text being printed in the browser > > > window. Can anyone point me in the right direction so that the cookie > > > > def writetocookie(number): > > > #writes the ID of the database entry to a cookie > > > cookie["dataid"]=number > > > print "Content-Type: text/html" > > > print > > > print "Set-Cookie: dataid=",cookie["dataid"].value > > > > I presume this is not the correct way to write a cookie, the examples > > > I have found online don't seem to provide much more information. > > > I don't know either if this is the right way, but surely the Set-Cookie > > header must appear *before* the blank line; that blank line separates the > > headers from the response body. > > > -- > > Gabriel Genellina > > Thanks, that seemed to work. > > rod Also how do I find out if a cookie has expired? I have tried various methods but to no avail? Cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
CGI with URL problem
-- sorry if this has shown up twice, but my browser crashed and ended
up posting the message when I hit the space bar for some odd reason.
Also it was not quite ready.
Hi,
I am writing a small CGI app which tests if another webpage exists,
the pages are on a Wiki system. Anyway when I run the same function
(see below) from within IDLE it is ok, however when it is run from
within the CGI script I get a socket error::
"URLError:
reason = "
I am not quite sure what is causing this, is there a special way of
dealing with such things from within CGI script? I have pasted the
offending function below, along with only the import statement which
relates to that function.
Thanks in advance for any help.
Kind regards,
rod
>From the CGI version:
from urllib2 import urlopen as urlopen
def urlexists(url):
path="http://x.y.z/wiki/index.php?title="+url
sock = urlopen(path)
page=sock.read()
if "There is currently no text in this page" in page:
return True
else:
return False
Ammended IDLE version:
from urllib2 import urlopen as urlopen
import os,sys
def urlexists(url):
path="http://x.y.z/wiki/index.php?title="+url
sock = urlopen(path)
page=sock.read()
if "There is currently no text in this page" in page:
print "found"
return True
else:
print "not found"
return False
if __name__=="__main__":
urlexists("cheese_test")
--
http://mail.python.org/mailman/listinfo/python-list
URL in CGI problems
Hi,
I am writing a small CGI app which tests if another webpage exists,
the pages are on a Wiki system. Anyway when I run the same function
(see below) from within IDLE it is ok, however when it is run from
within the CGI script I get a socket error::
"URLError:
reason = "
I am not quite sure what is causing this, is there a special way of
dealing with such things from within CHI script? I have pasted the
offending function below, along with only the import statement which
relates to that function.
Thanks in advance for any help.
Kind regards,
rod
>From CGI version:
from urllib2 import urlopen as urlopen
def urlexists(url):
path="http://x.y.z/wiki/index.php?title="+url
sock = urlopen(path)
page=sock.read()
if "There is currently no text in this page" in page:
print "found"
return True
else:
return False
Ammended IDLE version:
from urllib2 import urlopen as urlopen
import os,sys
def urlexists(url):
path="http://www.peachbase.org/peachbase/index.php?title="+url
sock = urlopen(path)
page=sock.read()
if "There is currently no text in this page" in page:
print "found"
return True
else:
print "not found"
return False
if __name__=="__main__":
urlexists("cheese_test")
--
http://mail.python.org/mailman/listinfo/python-list
Re: CGI with URL problem
Thanks for your reply, no one is running locally on my PC and the other as the default user which occurs when the script is run through a browser. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Running CGI from within CGI
I am new to using Python as a CGI platform, so please excuse me if
this is a dumb question.
Anyway I have written a series of web forms (with Python scripts)
which allow the user input but also retrieve data from a database. The
data entry stage works fine however retrieving data is a little more
tricky. However I need to find a way to call the scripts directly from
within other CGI's. At present when I go to the next page I call the
normal HTML page as below:
p = open('somefile.html')
some = p.read()
p.close()
print some
However I would like to execute a script instead so calling for
example myscript.py - thus populating the existing forms with data.
This does not seem to work when I modify the above method. Is there
another way to do it? Thanks in advance.
Kind regards,
rod
--
http://mail.python.org/mailman/listinfo/python-list
Re: Running CGI from within CGI
Thanks for the details, is execfile full of security issues or
something?
You are right about exploring templates, I may explore that later.
However I need to integrate the forms in with another system, which
will not be using templates. I suspect I may have taken the long way
round but I suppose it also means I learn a little more Python :-)
Cheers,
rod
On Feb 14, 3:26 pm, Bruno Desthuilliers wrote:
> rodmc a écrit :
>
>
>
> > I am new to using Python as a CGI platform, so please excuse me if
> > this is a dumb question.
>
> > Anyway I have written a series of web forms (with Python scripts)
> > which allow the user input but also retrieve data from a database. The
> > data entry stage works fine however retrieving data is a little more
> > tricky. However I need to find a way to call the scripts directly from
> > within other CGI's. At present when I go to the next page I call the
> > normal HTML page as below:
>
> > p = open('somefile.html')
> > some = p.read()
> > p.close()
> > print some
>
> > However I would like to execute a script instead so calling for
> > example myscript.py - thus populating the existing forms with data.
> > This does not seem to work when I modify the above method. Is there
> > another way to do it? Thanks in advance.
>
> The QuickAndDirtyWay(tm) would be to use execfile IIRC. But since you
> *don't* want to do it that way, the best thing to do would be to factor
> out common code into functions in a distinct module (or in as many
> modules as needed), then rewrite your cgi scripts so they import the
> relevant modules and call the appropriate functions.
>
> And while we're at it, I'd greatly recommand giving a look at the
> various templating packages around (may I recommand Mako ?) and the
> FormEncode package for HTTP forms conversion/validation ?
>
> HTH
--
http://mail.python.org/mailman/listinfo/python-list
URLlib2?
Hi, Probably a silly question but I am writing a CGI script which need to check the referring URL, can anyone provide any pointers? I have looked at URLLib2 and a couple of other libraries, but am slightly confused. Thanks in advance, rod -- http://mail.python.org/mailman/listinfo/python-list
Python CGI & Webpage with an Image
Hi, I have a set of CGI scripts set up and in one page (which is stored in an HTML file then printed via a python CGI) there is an image. However the image never displays, can anyone recommend a way round this problem? Kind regards, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Python CGI & Webpage with an Image
Hi,
Thanks for your very quick response. I have played around a bit more
so that both the image and HTML file are in the public_html folder.
They are called via python using a relative URL, and have permissions
set to 755. Within the HTML file the image is accessed using just
"banner.jpg". The actual page displays ok except for the image - so it
has the same problem as before. However when the same page is
displayed without running through a CGI it displays perfectly.
Kind regards,
rod
On Mar 6, 11:46 am, Bryan Olson <[EMAIL PROTECTED]> wrote:
> rodmc wrote:
>
> [...]
> > Python:
> >
> > f = open("finish.html")
> > doc = f.read()
> > f.close()
> > print doc
>
> You might need to start with:
>
> print "Content-Type: text/html"
> print
>
> Is "finish.html" in the right place? When you browse to your
> script, can you see that you're getting the html?
>
> > HTML:
> [...]
> >
> I suspect a server configuration and/or resource placement problem.
> The image has a relative URL, and the user's browser will look for
> it on the same path that it used to get the resource served by the
> cgi script, up to last '/'.
>
> Is banner.jpg in the right place, and is your web server configured
> to treat everything in that directory as a cgi script, and thus
> trying to execute the jpg? If one of those is the problem, just
> move banner.jpg, and/or change the relative URL. For example,
> SRC="../banner.jpg" will cause the browser to look for the jpg
> one directory above.
>
> Failing that, can look at the web server's log?
>
> --
> --Bryan
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python CGI & Webpage with an Image
Hi,
Good point, some code samples is probably required. Please note that
for reasons of integration with another system I am not using a
templating system.
Anyway I have copied them below:
Python:
f = open("finish.html")
doc = f.read()
f.close()
print doc
HTML:
Thank you for uploading your file
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python CGI & Webpage with an Image
> Is the cgi script in the same directory? The user's browser looks > for the jpg relative to the URL it used to get the page, which in > the case of the CGI script is the path to the script, not the > path to the html file. No the CGI script is in a different folder, I could move everything to the same folder I guess. > If server logs are hard to get or read, try my runcgi.py script: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/550822 Thanks, I will try this. Rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Help Starting Out
> Hi, I would like to start using Python, but am unsure where to begin. > I know how to look up a tutorial and learn the language, but not what > all technologies to use. I saw references to plain Python, Django, > and other things. Hi, For database stuff you can plug directly into either MySQL or SQLite. For MySQL you need to install a third party library which you can get from: http://sourceforge.net/projects/mysql-python I think SQLite support is now included in Python 2.5, all you need to do is type "import sqlite3", and away it goes. You will of course need to install SQLite, just search for it online. I found SQlite more than sufficient for any single user non-web based apps. On the client side you can use these library and if you like build a free standing app to run everything. For GUI toolkits you can do worse than download and install wxPython, which again is free (www.wxpython.org). If you want to dabble in games programming there is also PyGame. If you want to build free standing applications you can use Py2Exe (Windows) and Py2App (Mac), just Google them and they will appear. You may at times find Python a little slow, and you can even get round that problem in Windows and Intel based Macs by using Psyco (again just Google). It can speed up your code by quite a large margin. Hope these help you get started... Rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Help Starting Out
> Your best bets are probably Django, Pylons or web.py. But you should > learn enough of the core language itself before jumping in web stuff IMHO. Yes, a good point. If you are looking for general info then then "Dive Into Python" (a link is on the Python website) is a good start for people who are familiar with other programming languages. Otherwise I also found "Python in a Nutshell" useful. rod -- http://mail.python.org/mailman/listinfo/python-list
OS.remove and threads
Hi, I am writing a small application which uploads files in a thread via an ftp connection. However anytime I use the os.remove(filename) command to delete files the thread crashes, even if the file being removed has nothing to do with the one being uploaded. Are the OS commands incompatible with threads? By crashing I mean the thread stops uploading and an exception is produced. Also if the OS commands are in any other thread, they cause that thread to crash. I have tried using locks around the os.remove command but that also makes no difference. I am using: Mac OS 10.4.9 and Python 2.4.3 with Psyco. Kind regards, rod -- http://mail.python.org/mailman/listinfo/python-list
Download CGI
Hi, I am trying to figure out how to create a Python script which will open a file from a folder outwith the public_html path and serve it directly to the user for downloading. The aim being so that the users cannot see where the file is served from. Is there an easy way to do this, or an HTML header I am missing or an easy way in Python? Best, rod -- http://mail.python.org/mailman/listinfo/python-list
File Upload Size
Hi, Is there a way to get the size of a file on a remote machine before it is uploaded? I would like to write some form of status counter which is updated as a fie is uploaded, and also to use this feature to prevent files which are too big from being uploaded. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: File Upload Size
On 13 Oct, 00:10, Mike Driscoll <[EMAIL PROTECTED]> wrote: > On Oct 12, 9:34 am, rodmc <[EMAIL PROTECTED]> wrote: > > > Hi, > > > Is there a way to get the size of a file on a remote machine before it > > is uploaded? I would like to write some form of status counter which > > is updated as a fie is uploaded, and also to use this feature to > > prevent files which are too big from being uploaded. > > > Best, > > > rod > > Looks like ftplib does that. Check the > docs:http://www.python.org/doc/2.5.2/lib/module-ftplib.html > > Mike Hi Mike, Thanks for this information I will look at it. The only condition is that everything must run via a webpage. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: File Upload Size
On Oct 13, 11:55 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > rodmc wrote: > > On 13 Oct, 00:10, Mike Driscoll <[EMAIL PROTECTED]> wrote: > >> On Oct 12, 9:34 am, rodmc <[EMAIL PROTECTED]> wrote: > > >> > Hi, > > >> > Is there a way to get the size of a file on a remote machine before it > >> > is uploaded? I would like to write some form of status counter which > >> > is updated as a fie is uploaded, and also to use this feature to > >> > prevent files which are too big from being uploaded. > > >> > Best, > > >> > rod > > >> Looks like ftplib does that. Check the > >> docs:http://www.python.org/doc/2.5.2/lib/module-ftplib.html > > >> Mike > > > Hi Mike, > > > Thanks for this information I will look at it. The only condition is > > that everything must run via a webpage. > > Which is crucial information and rules out Mike's suggestion. > > And the answer is: no, you can't access file-attributes on remote machines. > HTTP does require a content-length header though. If that exceeds a certain > size, you can terminate the connection. > > You need to do that also if the client actually pushes more data than > announced. > > And progress-counting can be done by counting the already arrived data & > making e.g. an Ajax-Call to fetch that from the server. > > Diez Thanks. I have basic file uploading working, however is there a limit to what can be uploaded via form? It works perfectly for up to around 20MB then breaks. Also how do I retrieve the content-length header? I am quite new to HTTP programming so sorry for the naive questiomn. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: File Upload Size
Hi Diez, Thanks, I will look on Google again, to date though all examples I have used come up against similar problems. As for HTTP framework and libraries, I will see what is currently supported. At present I am using standard Python libraries. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
FTP via web browser
Hi, I have posted elsewhere about a related topic. But I an curious is it possible to set up a web form which people select a file for upload which is then upload it via FTP protocol to the web server - the entire process must be web based and not require an external FTP client. The reason for asking is that uploading large files via HTTP form post is very unreliable beyond say 20MB. Thanks in advance. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Mobile Devices
Hi, I have been scouting around online for information on how to use Python and a GUI toolikit to develop mobile devices. At present I am using wxPython for desktop apps and would like to continue using that if possible. Anyway, I would like to know what people would recommend for developing mobile applications which can run on Windows Mobile and Mac OS X (iPhone etc)? It would also be cool if the same apps could run where possible (or atleast part of them) on desktop machines as well. Any tips, experiences etc welcome. This is really to stimulate some general discussion. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Mobile Devices
Thanks for your reply, I may dig out my really old Symbian phone and try it out. rod -- http://mail.python.org/mailman/listinfo/python-list
Server applications - avoiding sleep
I have written a small server application (for Windows) which handles sending and receiving information from an instant messaging client and a database. This server needs to run 24/7, however it stops when the computer screen is locked. I assume there is a way to make it run in the background 24/7 but how do I go about doing this? At present the application runs from within a wxPython GUI, however this is only used to start and stop it. It could be entire faceless and the GUI only used to execute it. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Server applications - avoiding sleep
Hi, Thanks to both of you for your help. cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
Refreshing Active Desktop Window
I have written a small program which updates and HTML page in an active desktop (Internet Explorer) window. At present whenever it is refreshed it redraws the whole screen, I am using a very basic script from a Win32 example I found a while ago. Is there a way I can refresh the Window only and not the whole screen? Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Server applications - avoiding sleep
Hi Lev, Sounds interesting. As I am quite new to Python an example program would be most welcome. My email address is contained in the message. Best, rod -- http://mail.python.org/mailman/listinfo/python-list
Windows Services
Hello,
I am trying to figure out how to write a windows service, I am totally
new to it. I have written a simple test case, however it doesn't appear
to do anything. Although it installs and appears to start, when I run a
query of its status (using another app) it says it is not running. As
a note I am running it as the administrator in a Win2k machine to avoid
any problems with permissions - although I would rather not do this for
ever :-)
I install the software as follows:
python testservice.py install
python testservice.py start
I am sure I am missing something out as I am basically working from
code samples for other solutions which I have seen. In particular one
for getting CherryPy to run as a service.
When I have figured this all out I intend to add in some code I have
already written which runs a server application.
It may be all rather obvious but I am quite new Python (just a few
months) and totally new to Windows services.
Thanks in advance for any help.
Best,
Rod
import win32serviceutil
import win32service
import win32event
import os,sys
class helloworld:
def test(self):
x=1
filename=open("c:test.txt","w")
while x<10:
print >>filename,x
x=x+1
class MyService(win32serviceutil.ServiceFramework):
"""NT Service."""
_svc_name_ = "Test"
_svc_display_name_ = "Test"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
# create an event that SvcDoRun can wait on and SvcStop
# can set.
self.stop_event = win32event.CreateEvent(None, 0, 0, None)
def SvcDoRun(self):
print "got here"
helloworld.test()
win32event.WaitForSingleObject(self.stop_event,
win32event.INFINITE)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.stop_event)
if __name__ == '__main__':
win32serviceutil.HandleCommandL
--
http://mail.python.org/mailman/listinfo/python-list
Shipping Executables
Hi, I have been merrily programming away in Python now for a few years and have a couple of applications I would like to possibly publish at some point - with the exception of certain libraries they are more or less 100% Python. However I have read elsewhere online that Python due to it's architecture is not so good for this, especially as it is easier for people to hack into the code. Also where software requires some security aspects I guess it would also not be much use, is this correct? Anyway I would appreciate any views or tips that people have? Kind regards, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Shipping Executables
> > Hi Rod, > > The user's ability to hack into the code is usually considered one of > > the strengths of Python & open source software in general. Since most > > Python software that's distributed is open source, you're doing > > something different than most. It'd help if you explain how you want > > your software to differ from a typical open source distribution. Do you > > not want people to change the code? Are you worried about your code & > > ideas being stolen? Thanks to everyone for their replies. Normally I have no problem with adopting an open source model, indeed I usually encourage it. However the main problem was related to end- user licencing e.g. via some form of registration key. The other problem was related to end-user private data and sending this via a secure Internet connection. While I am ok with secure Internet connection side of it I was concerned that with the source code being available to others the security may in some way be reduced- however I note one reply which says this is not the case. Kind regards, rod -- http://mail.python.org/mailman/listinfo/python-list
