Here's some code I've recently done.
>From python (on your 'consumer') - this is how I do an HTTP get.
def HTTPGet(url, timeout)
import urllib2
#url = "http://www.google.com"
#timeout = 30
try:
response = urllib2.urlopen(url, None, timeout)
result = response.read()
if result:
return result, None
except urllib2.URLError, ex:
if hasattr(ex, "reason"):
print "HTTPGet: failed to reach a server."
print ex.reason
return None, ex.reason
elif hasattr(ex, "code"):
print "HTTPGet: The server couldn\'t fulfill the request."
print ex.code
return None, ex.code
Now, depending on your needs, 'result' may be just some plain text, xml, or
json - whatever works best for your needs.
This example does an HTTP GET, so of course be aware whatever information
you serve on the other side is publicly available. To secure it you'll
need to work out an authentication scheme. (x-auth headers or whatever)
Hope this helps!
S
On Fri, May 25, 2012 at 10:56 AM, Leandro Severino <
[email protected]> wrote:
> Hi Shannon,
>
> On 25 maio, 11:40, Shannon Cruey <[email protected]>
> wrote:
> > Not to pot too fine a point on it, but your question is too generic to be
> > answered. Web.py is a framework, and providing web services is very
> simple
> > and probably one of the top uses.
>
> OK,
>
> > Any web server that answers a request and returns data could be argued to
> > be a web service. Any program that does something with that response is
> a
> > consumer of that service. It's far too broad of a topic to answer they
> way
> > you've asked it. Every time I hit google, I'm optically scanning the
> > results of a web service and consuming it with my cranial computer. :-)
> >
>
> :), yes !.
>
> > Look here at the tutorial - you'll have a 'hello world' web service up
> and
> > running in minutes with web.py.
> >
> > http://webpy.org/docs/0.3/tutorial
> >
>
> yes, after of my post, I found a sample in the cookbook documentation
>
>
> > Now, if you wanna 'consume' that service, go ahead and do it with
> whatever
> > technology you want. From the command line using curl, from python using
> > urllib, or from a web browser using ajax. The options are limitless.
> >
>
> OK, all right.
>
> Well, I have a scenario where I have two apps(developed with web.py)
> and these apps needs share data (and these are hosted in different
> hosts), but this apps don't need know the business rules of each, then
> I think that a producer of webservice and a consumer of webservice is
> the solution (feel free to correct me).
>
> Well, with the cookbook documentation I have a solution for the
> producer, then my doubt now is how to consumer this webservice in my
> web.py app ?
>
> A sample code, tip or suggestion ?
>
> thank you so much,
>
> Leandro.
>
> --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/webpy?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.