[Tutor] File upload from python shell

2007-10-13 Thread Paulino
Hello!


How can I upload a file from python?

If it is a form to fill with values it's simple:


urlopen("http://site.com/action?key1=value1;key2=value2";) and I get the 
form filled.


What about uploading a file programmaticaly?


Thank you

Paulino
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] File upload from python shell

2007-10-14 Thread Paulino
Luke Paireepinart escreveu:
> Paulino wrote:
>> Hello!
>>
>>
>> How can I upload a file from python?
>>
>> If it is a form to fill with values it's simple:
>>
>>
>> urlopen("http://site.com/action?key1=value1;key2=value2";) and I get 
>> the form filled.
>>   
> Only if the form uses the GET method.
> If your file upload form used GET, you could upload your file like 
> this as well (after base-64 encoding it.)
> I recommend reading the Wikipedia articles on GET and POST so you can 
> know the difference.
>>
>> What about uploading a file programmaticaly?
>>   
> file uploads usually use the POST method, not GET.
> they're generally the same thing as text or radiobutton form entries, 
> except their input type is set to file,
> so that it's base-64 encoded so that there's no errors in transmission.
> basically you'll have to look at a few things:
> 1. how the POST method is structured.
> 2. Which keys your file-uploading page wants.
> 3. how to base-64 encode your file.
> 4. how to measure the length of all your keys and data so that you can 
> set content-length header correctly.
> 5. how to submit this new http request properly.
>
> What are you trying to upload to?
> if it's ImageShack by any coincidence, I have some code that does that 
> already.
> If it's something else, the code would probably be similar.
> Let me know if you want to take a look at that.
> -Luke
>
>
I want to upload pdf files, to an intranet server, that I also control.

Yes I think it would be very usefull to have a look at your code.

The urlopen function can take an optional data parameter that is used to 
specify a POST request, but i couldn't find information about how to set 
the data parameter properly.

Thank You
Paulino
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] File upload from python shell

2007-10-15 Thread Paulino
Kent Johnson escreveu:
> Paulino wrote:
>> Hello!
>>
>>
>> How can I upload a file from python?
>>
>> If it is a form to fill with values it's simple:
>>
>>
>> urlopen("http://site.com/action?key1=value1;key2=value2";) and I get 
>> the form filled.
>>
>>
>> What about uploading a file programmaticaly?
>
> This might help:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306
>
> Kent
>
>

Thank You very much Luke, Alan, David and Kent.


I used Nokia's forum recipe (sugested by David) it's very simple and 
works perfectly!

here is it (a few variables changed)


import httplib, urllib
import base64, os.path
 
 
def uploadToURL( aPath ):
# read the binary data of the pdf
data = open(aPath, 'rb').read()
# encoded it to base64
encodedData = base64.encodestring( data )
headers = { "Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"  }
 
params = urllib.urlencode({ 'filename': os.path.split(aPath)[1],
'file_data':encodedData})
 
conn = httplib.HTTPConnection( "localhost:8080" )
conn.request( "POST", "/rendas/rec/uploadtxt", params, headers )
response = conn.getresponse( )
# returns "True" or "False" if failed
print response.read( )
# status for debugging
#print response.status
conn.close( )
 
 
if __name__ == "__main__":
uploadToURL("/home/paulino/ola230.pdf")




And here is the turbogears server method that handles the file:


@expose()
def uploadtxt(self, file_data, **kw):
data = base64.decodestring(file_data)
f = open(kw['filename'], 'wb')
f.write(data)
f.close()
return "Success"
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] e-learning Python

2006-09-28 Thread Paulino




Yes I'm looking for something more interactive, but didn't find
anything yet.

Lerning by one's self has it's limitations...




[EMAIL PROTECTED] escreveu:

  

Message: 1
Date: Tue, 26 Sep 2006 10:05:56 + (UTC)
From: Andrei <[EMAIL PROTECTED]>
Subject: Re: [Tutor] e-learning Python
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=us-ascii

PA  sapo.pt> writes:

  
  
Is there any site offering e-learning about Python?

If not, the PSF should do it!

  
  
If you mean if there are any online tutorials: lots of them. Here's a very large
list: http://www.awaretek.com/tutorials.html

Yours,

Andrei



  
  

Message: 3
Date: Tue, 26 Sep 2006 08:47:28 -0700
From: "Nathan  Botts" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] e-learning Python (PA)
To: 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain;	charset="us-ascii"

That might depend on what you consider eLearning. I've found that the "How
to Think Like a Computer Scientist"
(http://ibiblio.org/obp/thinkCS/python/english2e/html/index.html) online
book is a great learning guide. Or are you looking for something more
interactive?

-Nathan



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] database web app, what tool?

2006-10-01 Thread Paulino
Hi!

Im a very biginner in programming and I started with python, witch I 
found much easier tahn i thought.

I want to build an intranet page in my organization that shows some data 
from our financial aplication's database.

For the starting point I would like it to show invoices lists per 
supplier and link each line to a pdf image of the selected invoice that 
is stored in a determined folder.

The aim is only to make querys and show the results. No updates, nor 
insert's

The database is MS SQL 2005



Right now I connect to the database via pymssql, and i can retrieve data 
and send it to a wx.Grid or to a reportlab pdf file, with platypus 
tables (a couple of months ago i would say i'd never be able to do it... 
and now i want to do more...)

Now I want to send it to the browser so the administration can see it 
every time they need.


What tool is more suitable?

There are so many options!

Zope-Plone have it's own web server, so less config is required. But i 
can't find any recipe or tutorial usefull for this task...

there is also django, turbogears, webware, apache and mod-python.....


Thank you


Paulino


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] tkinter

2006-10-09 Thread Paulino
Hi Abdullah!

There is a kind of grid for tkinter that you can find online in the 
python cookbook, search for MultiListbox.

But if you really want a spreadsheet like grid, you'd rather use wx.grid 
from wxPython.

wxPython is much more powerfull than tkinter and is as easy to learn.
You can find lots od doc's in www.wxpython.org.



> Date: Mon, 9 Oct 2006 14:23:32 +0300
> From: "Abdullah Anar" <[EMAIL PROTECTED]>
> Subject: [Tutor] tkinter
> To: tutor@python.org
> Message-ID:
>   <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="iso-8859-1"
>
> hello,
>
> We try to build new software using python and tkinter. We would like to
> enter some fields using grid style. I mean we want to use rows to see old
> entries and to enter new one. I hope I could explain, because it also is
> not  easy. I know there is grid to locate buttons, labels and something like
> these. I hope I could explain I did not mean this grid which is using
> instead of pack.
>
> we wonder if there is already some classes or widgets to do this.
>
> thanks for help from now
>
> Abdullah Anar
> -- next part --
> An HTML attachment was scrubbed...
> URL: 
> http://mail.python.org/pipermail/tutor/attachments/20061009/41a5ee23/attachment-0001.html
>  
>
>   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Exception and sys.exit() in a cgi script

2006-10-15 Thread Paulino
This is a peace of a CGI script i have.

1 import cgi
2 form=cgi.FieldStorage()
3 try :
4 ano=form["ano"].value
5 conta=form["conta"].value
6 except KeyError :
7 print 'Please enter values in the
fields '
8 sys.exit(0)


When the excption occurs, no message is shown on the browser.

If I run the script with IDLE, the message is printed and then the
script exits.

What's wrong here?



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to open file in Excel/Calc spreadsheet?

2006-10-15 Thread Paulino




Very simple: os.startfile([file])

ex:
>>> import os
>>> os.startfile("d:\\documentos\\eleicoes2005-dn.xls")

It works with any file tipe in windows, the file is opened with it's associated application.




Basil Shubin wrote:
> Hi ,friends!
> 
> How I can open Excel or OOCalc spreadsheet file 'remotely' from python 
> programm? I mean how to execute Excel or Calc with appropriate 
> spreadsheet file?




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Exception and sys.exit() in a cgi script

2006-10-15 Thread Paulino




Thank you,

Yes I have other scripts working fine.

The OS is WXP and the server is the python's CGIHTTPserver (for an intranet use only)


-
Hi Paulino,

> This is a peace of a CGI script i have.
> 
> 1 import cgi
> 2 form=cgi.FieldStorage()
> 3 try :
> 4 ano=form["ano"].value
> 5 conta=form["conta"].value
> 6 except KeyError :
> 7 print 'Please enter values in the
> fields '
> 8 sys.exit(0)
> 
> 
> When the excption occurs, no message is shown on the browser.

Can you tell us a bit more about the set up?
What OS? What web server? 

Can you get any other python CGI scripts running correctly?

> If I run the script with IDLE, the message is printed and then the
> script exits.

The IDE environment is very different to a web server environment.

You should only treat IDLE as a first approximation when 
developing Web scripts. You can use the OS prompt for a slightly 
better approximation provided you set some environment variables 
first, but ultimately you need to test on the web server you will 
be using.

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] CGIHTTPServer - redirect output to a log file

2006-10-15 Thread Paulino
How can I redirect the output of an CGIHTTPServer from the console to a 
logfile?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGIHTTPServer - redirect output to a log file

2006-10-15 Thread Paulino
well, I'm running this CGIserver on windows...

Glenn T Norton escreveu:
> Paulino wrote:
>
>> How can I redirect the output of an CGIHTTPServer from the console to 
>> a logfile?
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>  
>>
> You can start it from a shell script
> #!/bin/sh
> ./MyWebServer.py 2>>/path/to/output.log
>
> Good Luck,
> Glenn
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Exception and sys.exit() in a cgi script

2006-10-21 Thread Paulino






  Mike Hansen 
Mike.Hansen at atmel.com
   

Mon Oct 16 18:43:29 CEST 2006
> This is a peace of a CGI script i have.
> 
> 1 import cgi
> 2 form=cgi.FieldStorage()
> 3 try :
> 4 ano=form["ano"].value
> 5 conta=form["conta"].value
> 6 except KeyError :
> 7 print 'Please enter values in the
> fields '
> 8 sys.exit(0)
> 
> 
> When the excption occurs, no message is shown on the browser.
> 
> If I run the script with IDLE, the message is printed and then the
> script exits.
> 
> What's wrong here?
> 
> 
> 
> ___
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
  I'm catching up on the weekend's tutor messages.

import cgitb; cgitb.enable()
That spits errors to the web page which is great for debugging cgi
scripts.

I think you need
print "Content-Type: text/html\n\n" 
http://docs.python.org/lib/cgi-intro.html

http://docs.python.org/lib/node560.html

Mike


Thats not the point (sorry).

when all the values are provided in the form (no excetion is raised) it
runs as expected!

The point is when one of the values "ano", "conta" is missing in the
form, I want the error message to be shown on the browser, and the
script to stop running.

When there is an exception, the script actually stops running, but no
message is sent to the browser.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me.. problem in building calculator application

2006-10-26 Thread Paulino

>
> Message: 7
> Date: Thu, 26 Oct 2006 13:31:37 +0100
> From: "Asrarahmed Kadri" <[EMAIL PROTECTED]>
> Subject: [Tutor] Help me.. problem in building calculator application
> To: pythontutor 
> Message-ID:
>   <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi folks,
>
> I am trying to build a rudimentary calculator application using Tkinter...
>
>   
Hi, Asrar!

Try this article instead:

http://www.devshed.com/c/a/Python/Designing-a-Calculator-in-wxPython/


Paulino

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cgi form field and popup window

2006-10-26 Thread Paulino






  
paulino wrote:
  
  
I would like to have a popup window to show the possible options to a form field
(supplier ID) and that by clicking on the desired item, the field is
automatically filled. The options are a database field values.

I wonder if this is possible to do with python (point me some resources please),
or have I to deal with _javascript_ ?

  
  
The browser-side programming has to be in _javascript_. The server-side 
program that sends the _javascript_ and the list of options to the browser 
can be in Python.

You might want to look at the TurboGears widget set which provides many 
browser-side widgets that are configured from Python. Widgets are part 
of TG 1.0. Unfortunately the docs seem to be a bit thin and sorting it 
all out is probably not a beginner project.
http://www.turbogears.org/
http://tgwidgets.toscat.net/

Kent


  

Many thanks, Kent,
that’s what
I was afraid of.

Well an alternative would be to use a drop down box with all the
suppliers ID’s
as options - a few thousands, is it viable? But this way the user can
not
introduce manually any ID, he would be forced to pick one from the drop
down
box.
 
In order to
give users booth possibilities, I can put an input field and a drop
down box that
would be dealt by a try / except clause. 
what do you think?


Paulino


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to kill an app from python on windows?

2006-12-02 Thread Paulino
To launch an app one can state os.startfile('hello.pdf') and the file is 
opened in acrobat .


And how can I kill the app from python, in order to, for instance, 
rename the file?


Is it possible?

thanks
Paulino
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to kill an app from python on windows? (Tim Golden)

2006-12-05 Thread Paulino
[EMAIL PROTECTED] escreveu:
>
>1. Re: How to kill an app from python on windows? (Tim Golden)
>   
>
> This link may get you started:
>
> http://effbot.org/pyfaq/how-do-i-emulate-os-kill-in-windows.htm
>
> although it may not apply, depending on the exact
> circumstances of what you're doing.
>
> TJG
>
> 
>   
Thank you Tim,

How do i get the pid of the process?


Paulino
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Graphics with Python: wxPython vs. tkinter vs., PyCairo vs. PyX vs...

2007-01-18 Thread Paulino
There is also PyQt4 which is my favorite. I'm a beginner in programming 
I tryed first PyQt and I gave up because it seemed so complicated. Then 
I've played a litle with tkinter which I think is very poor. I moved to 
wxpython which as a learning curve similar to that of tkinter, but a 
wider set of widgets available.

Then o tryed again PyQt and it wasn't complicated anymore! PyQt as a 
even wider set of wigets than wxpy but the BIG advantage is QtDesigner 
which you can use to design your interfaces and then you only have to 
code the methods to the actions you want the widgets to perform.

Good luck

Paulino

> Date: Wed, 17 Jan 2007 14:09:57 -0600
> From: "Vijay Pattisapu" <[EMAIL PROTECTED]>
> Subject: [Tutor] Graphics with Python: wxPython vs. tkinter vs.
>   PyCairo vs. PyX vs...
> To: tutor@python.org
> Message-ID:
>   <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hey friends--
>
> I've been looking through the archives and haven't found any
> comparative evaluation of Python graphics libraries...
>
> Which is the best (or your favorite), and for what tasks?
>
> Thanks a lot!
> Vijay
>
>   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Redirect from a CGI script

2007-01-18 Thread Paulino
How can i redirect to another URL from a python CGI script.

Is's suposed to be as simply as:

print "Location : http://newurl "
It's not working.

this simple code does't work - 
'print "Content-Type:text/html\n\n"
'print "Location : /cgi-bin/ecodiv.pyw "
'print

I use CGIHTTPServer, the server script is as follows:

'from BaseHTTPServer import HTTPServer
'from CGIHTTPServer import CGIHTTPRequestHandler
'HTTPServer(("localhost", 80), CGIHTTPRequestHandler).serve_forever()

instead of redirecting, it only prints 'Location : /cgi-bin/ecodiv.pyw' inthe
browser

Paulino


___

O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Redirect from a CGI script

2007-01-19 Thread Paulino

Thank you Andre,

well it doesn't work either!

Paulino

Andre Engels escreveu:
2007/1/18, Paulino <[EMAIL PROTECTED]>:

How can i redirect to another URL from a python CGI script.

Is's suposed to be as simply as:

print "Location : http://newurl "
It's not working.

this simple code does't work - < redir.pyw>
'print "Content-Type:text/html\n\n"
'print "Location : /cgi-bin/ecodiv.pyw "
'print

I use CGIHTTPServer, the server script is as follows:

'from BaseHTTPServer import HTTPServer
'from CGIHTTPServer import CGIHTTPRequestHandler
'HTTPServer(("localhost", 80), CGIHTTPRequestHandler).serve_forever()

instead of redirecting, it only prints 'Location :
/cgi-bin/ecodiv.pyw' inthe
browser



I haven't tested it, but I think I had a similar error recently, and 
that was solved by removing the \n\n at the end of the Content-Type 
line. You could try that.





--
Andre Engels, [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
ICQ: 6260644  --  Skype: a_engels 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Redirect from a CGI script

2007-01-20 Thread Paulino

Still doesn't work.

This should be a server issue, once I use a very basic server:

'from BaseHTTPServer import HTTPServer 
'from CGIHTTPServer import CGIHTTPRequestHandler

'HTTPServer(("localhost", 80),CGIHTTPRequestHandler).serve_forever()

I tryed also with the Karrigel embeded server and nothing happened...

I tryed all the sugestions from Andre with no succes.

The cgi script as only these two lines:
'print "Content-type:text/html\r\n"
'print "Location:http://python.org/\r\n\r";

I have a Win Xp pro machine with Python2.5.

Paulino

On Sat, 2007-01-20 at 02:10 +, Paulino wrote:
  

Thank you Andre,

well it doesn't work either!



This works, 


#!/usr/bin/python
print "Location:http://python.org/\r\n\r";

as does this

#!/usr/bin/python
print "Content-type:text/html\r"
print "Location:http://python.org/\r\n\r";


Tested using Apache on Linux.  A redirect should have a 3xx status.
Apache saw the location header and fixed the status to be 302.  My
browser (firefox) received the 302 status with the new location and
requested the new URL.

Each header line should be separated by \r\n.  A Python print on linux
will only output \n.  In actual practice, that appears to work OK.
either the browsers tolerate the missing \r or Apache fixes the data
stream.

Firefox plugins called tamperdata and liveheaders can be very helpful
for debugging these kinds of interactions.

Get the redirect to a real web site working.  Then fix it to redirect to
your script.  Use tamperdata to see what is going on if you have trouble
making it work.

  

Paulino


Andre Engels escreveu:
2007/1/18, Paulino <[EMAIL PROTECTED]>: 
How can i redirect to another URL from a python CGI script.

Is's suposed to be as simply as:

print "Location : http://newurl "

It's not working.

this simple code does't work - < redir.pyw>

'print "Content-Type:text/html\n\n"
'print "Location : /cgi-bin/ecodiv.pyw "
'print

I use CGIHTTPServer, the server script is as follows:

'from BaseHTTPServer import HTTPServer 
'from CGIHTTPServer import CGIHTTPRequestHandler

'HTTPServer(("localhost", 80),
CGIHTTPRequestHandler).serve_forever()

instead of redirecting, it only prints
'Location : /cgi-bin/ecodiv.pyw' inthe 
browser



I haven't tested it, but I think I had a similar error recently, and
that was solved by removing the \n\n at the end of the Content-Type
line. You could try that.






--
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
  

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] same output on diferent sys.stdout.encodings

2007-02-07 Thread Paulino
Hi everyone!

I have some strings that include special characters, to be displayed in 
widget labels ( PyQt4 ).
The output changes in diferent OS's due to diferent sys.stdout encoding

Not only the labels in the GUI change, but the source file strings are 
altered when I move from win to linux and vice-versa.

The solution I found for now was to replace the special characters in 
the source file string for their representation:
I replaced "é" (e acute ) by "\xe9" wich correpsond to chr(233) in the 
cp1252 encoding.

The character é (e acute) in linux is not recognized in the source file, 
neither in IDLE nor in Kate
My win sys.stdout.encoding is cp850 and the linux one is utf-8

Now I have "d\xe9bito" instead of "débito" (debit in portuguese). By 
passing the string through unicode with the convinient encoding, I 
ensure the labels are exibithed the same  in every OS but, this way the 
code is not very readable.

Is there a way of solving this, keeping the more readable?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] same output on diferent sys.stdout.encodings

2007-02-08 Thread Paulino
Yes I have that declaration in my script.

Paulino


> Send Tutor mailing list submissions to
>   tutor@python.org
>
>   

# -*- coding: iso-8859-1 -*-

If you put this at the first line of your .py files (of course replace 
iso-8859-1 with whatever
encoding you use) I think this should do the trick.

I hope this helps

Michael


--

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] same output on diferent sys.stdout.encodings

2007-02-08 Thread Paulino
Yes that is the problem.

But I canot control all the the encodings in every PC that the script is 
to be run...

Paulino


Kent Johnson escreveu:
>
> I think the problem you are having is with the source code encoding, 
> not sys.stdout.encoding. Probably your editor on linux expects a 
> different file encoding than what you are using in Windows. Your 
> windows editor is probably using cp1252; perhaps the linux editor 
> expects utf-8.
>
> You need to get the editors to agree on the source code encoding. Then 
> put the coding declaration at the top of the file as Michael suggested.
>
> Kent
>
>
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor