HTTPError... read the response body?

2009-03-02 Thread Stuart Davenport
Hi There,

I am trying to connect to a web service but I am getting HTTP 400, I
am not too concerned about the HTTP error - but what I'd like to know
if there is anyway I can read the response body in the HTTP 400 or 500
case? Does the HTTPError allow this? or the urllib2 in anyway?

This is what I have at the moment...

import sys, urllib2
import socket

class APIConnector:
def connect(*args):
length = len(args[2])
headers = {"Content-Length": length, "Content-Type":
"text/xml", "SOAPAction": "\"http://some.api.com/RemovedAction\""}

try:
#url, body, headers
rq = urllib2.Request(args[1], args[3],
headers)
rs = urllib2.urlopen(rq)

print rs.read()
except urllib2.HTTPError, e:
conn = e
print 'error', conn.code, 'message: ',
conn.msg, 'filename: ', conn.filename, 'headers: ', conn.hdrs, 'body:
', conn.read()

I thought that conn.read() may show the body, but it seems not... Can
anyone help please, or suggest another way around? I am using python
2.5 installed with MAC OS X Leopard.


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


Re: HTTPError... read the response body?

2009-03-03 Thread Stuart Davenport
On Mar 2, 11:50 pm, Wojtek Walczak  wrote:
> On Mon, 2 Mar 2009 14:29:12 -0800 (PST), Stuart Davenport wrote:
>
> Hi,
>
> > I am trying to connect to a web service but I am getting HTTP 400, I
> > am not too concerned about the HTTP error - but what I'd like to know
> > if there is anyway I can read the response body in the HTTP 400 or 500
> > case? Does the HTTPError allow this? or the urllib2 in anyway?
>
> HTTP error 400 means 'bad request', so it's almost certainly
> your mistake.
>
> >                         #url, body, headers
> >                         rq = urllib2.Request(args[1], args[3], headers)
>
> Is args[1] a valid URL? And are you sure that you want to send
> something to the web serwer? By specifying the second argument
> (args[3]) you're asking python to send HTTP "POST" request,
> not "GET".
>
> --
> Regards,
> Wojtek Walczak,http://tosh.pl/gminick/

Hi Wojtek,

Yes, the args[1] is a valid url (I've printed it out to check) and
thats correct, I do want to initiate a POST request by passing over
the SOAP Envelope in the request. All I'd like to know if there is
anyway to read the body of an HTTP Error, so for instance, if I were
to recieve a 404 - I'd like to see the content that the server returns
with a 404 error.
--
http://mail.python.org/mailman/listinfo/python-list


How to create a virtual serial port?

2009-04-10 Thread Stuart Davenport
Hi,

I am trying to work out if its possible, to create a virtual serial
port with Python? Would anyone know how to go about this in code? Any
help would be greatly appreciated! :)

I have a had a google and the topics returned only seem to reflect
"reading" serial port data, particularly pySerial results...

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


Re: How to create a virtual serial port?

2009-04-10 Thread Stuart Davenport
On 10 Apr, 20:45, Scott David Daniels  wrote:
> Stuart Davenport wrote:
> > Hi,
>
> > I am trying to work out if its possible, to create a virtual serial
> > port with Python? Would anyone know how to go about this in code? Any
> > help would be greatly appreciated! :)
>
> > I have a had a google and the topics returned only seem to reflect
> > "reading" serial port data, particularly pySerial results...
>
> > Cheers
> > Stu
>
> Well, search for Smart Questions.  I have no idea what your OS is, nor
> what level of "virtual serial port" you want/need.  All anyone could
> do with your current request is guess what you need and try to steer you
> towards it.
>
> --Scott David Daniels
> scott.dani...@acm.org

Scott, totally fair point - a little candid, but fair...

I'm on a OS X, python 2.5. Basically I will have a remote application
pushing data (GPS) over the network to a python application I have
running on my Mac, I want this python application to again push the
data on to a "virtual serial port". Then the GPS program I have
running on my MAC, RouteBuddy, can read the data from that serial port
as standard.

The only part I am concerned about here though, is if I can create a
serial port virtually and push data out of it?

Hope that defines a little more clarity for yourself.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to create a virtual serial port?

2009-04-11 Thread Stuart Davenport
On 11 Apr, 08:52, Scott David Daniels  wrote:
> Stuart Davenport wrote:
> > ... I'm on a OS X, python 2.5. Basically I will have a remote application
> > pushing data (GPS) over the network to a python application I have
> > running on my Mac, I want this python application to again push the
> > data on to a "virtual serial port". Then the GPS program I have
> > running on my MAC, RouteBuddy, can read the data from that serial port
> > as standard.
>
> > The only part I am concerned about here though, is if I can create a
> > serial port virtually and push data out of it?
>
> OK, this is a Max OS/X question.  Does "RouteBuddy" have any other way
> to get data except from the serial port?  Does the mac have a serial
> port?or are you talking "serial port over USB" (which would be an
> entirely different kettle of fish).  With that out of the wa, I'd try
> to ask some Mac guys if the ponying up is possible, and if so how to
> do it in _any_ language (likely they'll have an Objective C way).
> Then pop back over here (or even better a python-mac list, where
> they'll be familiar with how to do lots of stuff) and you can get
> help getting python to either do the same thing or talk to a bit
> of code that does the byte-transfers.
>
> --Scott David Daniels
> scott.dani...@acm.org

Sadly RouteBuddy cannot retrieve data by other means...

Scott, many thanks for the advice. Will try to find a more specific
forum of conversation.

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


Re: How to create a virtual serial port?

2009-04-12 Thread Stuart Davenport
On Apr 11, 6:56 pm, Grant Edwards  wrote:
> On 2009-04-11, Grant Edwards  wrote:
>
> > You can write a port redirector in user-space in MS-Windows,
> > but you can't in Linux/Unix.  On Unix systems you have to
> > write a kernel module that sits below the tty layer.
>
> Perhaps I should elucidate further.
>
> That's what the "pty" driver on Unix is: a kernel module that
> sits underneath the tty layer where the "normal" serial-port
> UART drivers sit.
>
> However, Unix pty drivers only handles a subset of the normal
> serial-port API.  [I'm not sure why pty drivers have never been
> "finished" so that they fully emulate a serial port, but it's
> been that way for 20+ years].
>
> If RouteBuddy doesn't try to do things like get/set modem
> control/status lines, then the OP might be able to use a pty.
>
> Each pty consists of two devices: a master end and a slave end.
> RouteBuddy would be told to use the slave end, and the OP would
> write a program that would transfer data between a network
> connection and the master end.
>
> A pty devices is what is used by programs like xterm to run
> programs like bash.  Xterm transfers data between a network
> connection and the master end of a pty.  Bash is connected to
> the slave end of that pty and "thinks" it's connected to a
> serial port.  Bash uses little of the serial port API, so it's
> happy with the limited API provided by a pty slave-end.
>
> --
> Grant

Grant - HERO! THIS EXACTLY WHAT I WANT TO DO...

I didn't realise people were still posting on this thread and have
spent the last 3 hours trying to get some example code to create a
pseudo TTY (pty) in Python, I get that I have to use the pty module,
but finding an example is like searching for... lets go festing ...an
easter egg in a forest ;)

You wouldn't have any pointers to initiating a PTY and how to write to
it? This is all I want to achieve.


My point in all this is actually that I ordered a USB GPS Receiver and
it wont arrive for another two weeks, being my impatient self, I am
writing an app for my iPhone to broadcast its GPS location over the
network to my laptop. I then want to get this data into the NMEA
format and push this data onto a PTY - this will in-effect replace the
USB GPS Receiver and the GPS software can read it :)

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