Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29152

Re: Batching HTTP requests with httplib (Python 2.7)

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <dwightdhutto@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'things.': 0.05; 'elegant': 0.07; 'executed': 0.07; 'params': 0.07; 'ugly': 0.07; 'works.': 0.07; 'wrapper': 0.07; 'function:': 0.09; 'iterate': 0.09; 'received:mail-vb0-f46.google.com': 0.09; 'subject:2.7': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'library': 0.15; 'essentials': 0.16; 'eval': 0.16; 'hell.': 0.16; 'sequential': 0.16; 'subject:requests': 0.16; 'received:209.85.212.46': 0.18; '(or': 0.18; 'define': 0.20; 'written': 0.20; 'bit': 0.21; 'lets': 0.22; 'runs': 0.22; 'cc:2**0': 0.23; 'matching': 0.23; 'task': 0.23; 'cc:no real name:2**0': 0.24; 'command': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'wondering': 0.26; 'appreciated': 0.27; 'message- id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'skip:( 20': 0.28; 'credentials': 0.29; 'probably': 0.29; "i'm": 0.29; 'maybe': 0.29; 'worked': 0.30; 'code': 0.31; 'print': 0.32; 'certain': 0.33; 'problem': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'whatever': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'subject:with': 0.36; 'subject: (': 0.36; 'moment': 0.37; 'ones': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'positive': 0.38; 'some': 0.38; 'header:Received:5': 0.40; 'help': 0.40; 'your': 0.60; 'most': 0.61; 'places': 0.61; 'more': 0.63; 'services': 0.64; ':).': 0.84; 'calls,': 0.84; 'services?': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=CMP0qfa1jDhYBNF48FY21YzsZesxsoP1Dn4p1DMJxNE=; b=x0Z15qXTgbjelRcRsLDufsxaEui7wtnsbzTh1HjPTctTLuUxXus19y8+pFg+K+wyP9 CHnMeW9w0odI+GxuiRFRivxarjpHbeR3c2IlOFTLm3ld8qR0xodSuIB3H1902FNTr+fE 2hBsDr4R5UOJuCsDI4V1hIzsbzJP91Ba26xw7has36eLWLwaSJ7BkBtHs8H2VS+LAsJl lJvY+BYqejva9YzDC6nm0gN4OQEneGQn3kK3Dk7xj06eQAdkrINXRfPACb36STYHEVBn roXQiu5PI7sTX2hBPRJXBDBPFpXfaHflCbknzO2kGmIALQSLIfIoor6ZL92NX5VYp4T3 305g==
MIME-Version 1.0
In-Reply-To <k2uurd$re8$1@speranza.aioe.org>
References <k2t90g$4e4$1@speranza.aioe.org> <mailman.659.1347589892.27098.python-list@python.org> <k2uurd$re8$1@speranza.aioe.org>
Date Fri, 14 Sep 2012 06:56:30 -0400
Subject Re: Batching HTTP requests with httplib (Python 2.7)
From Dwight Hutto <dwightdhutto@gmail.com>
To Chicken McNuggets <chicken@mcnuggets.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.695.1347620198.27098.python-list@python.org> (permalink)
Lines 69
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347620198 news.xs4all.nl 6896 [2001:888:2000:d::a6]:60507
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29152

Show key headers only | View raw


>> | The problem with most web services is that they require a list of
>> | sequential commands to be executed in a certain order to complete a
>> | given task (or at least the one I am using does) so having to manually
>> | call each command is a bit of a pain. How would you go about the design
>> | of a library to interact with these services?
>> |
>> | Any help is greatly appreciated :).
>>
>> Maybe I'm missing something. What's hard about:
>>
>>    - wrapping the web services calls in a simple wrapper which
>>      composes the call, runs it, and returns the result parts
>>      This lets you hide all the waffle about the base URL,
>>      credentials etc in the wrapper and only supply the essentials
>>      at call time.
>>
>>    - writing your workflow thing then as a simple function:
>>
>>        def doit(...):
>>          web_service_call1(...)
>>          web_service_call2(...)
>>          web_service_call3(...)
>>
>>      with whatever internal control is required?
>>
>> This has worked for me for simple things.
>>
>> What am I missing about the larger context?
>>
>
> That is what I have at the moment but it is ugly as hell. I was wondering if
> there was a somewhat more elegant solution that I was missing.
> --

Well if the code works it works. There probably is a better way than
what I came up with:


def web_service_call0(y):
	print "Service call = %i)" % y

def web_service_call1(y):
	print "Service call = %i)" % y

def web_service_call2(y):
	print "Service call = %i)" % y

def web_service_call3(y):
	print "Service call = %i)" % y

def web_service_call4(y):
	print "Service call = %i)" % y

service_num_list = [num for num in range(0,5)]
for service_num in service_num_list:
	eval("web_service_call%i(%i)" % (service_num,service_num))



I just define the service calls, and iterate through them with an eval
that places in the service call num, but you would have to have a
matching list of the params that would go with each one.

I'm almost positive there will be some more well written ones on the way.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Batching HTTP requests with httplib (Python 2.7) Chicken McNuggets <chicken@mcnuggets.com> - 2012-09-13 19:34 +0100
  Re: Batching HTTP requests with httplib (Python 2.7) Cameron Simpson <cs@zip.com.au> - 2012-09-14 12:31 +1000
    Re: Batching HTTP requests with httplib (Python 2.7) Chicken McNuggets <chicken@mcnuggets.com> - 2012-09-14 10:53 +0100
      Re: Batching HTTP requests with httplib (Python 2.7) Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-14 06:56 -0400
      Re: Batching HTTP requests with httplib (Python 2.7) Cameron Simpson <cs@zip.com.au> - 2012-09-15 19:30 +1000
      Re: Batching HTTP requests with httplib (Python 2.7) Xavier Combelle <xavier.combelle@free.fr> - 2012-09-14 13:46 +0200
        Re: Batching HTTP requests with httplib (Python 2.7) Neil Cerutti <neilc@norwich.edu> - 2012-09-18 12:40 +0000

csiph-web