[zope2-tracker] [Bug 1152193] [NEW] ZPublisher.Client.call discards HTTP method argument

l0b0 victor.engmark at gmail.com
Thu Mar 7 14:30:45 UTC 2013


Public bug reported:

>From <http://stackoverflow.com/questions/15272221/how-to-set-http-
method-with-zpublisher-client-call>:

I've tried calling Zope 2.10.9's ZPublisher.Client.call
<https://github.com/zopefoundation/Zope/blob/master/src/ZPublisher/Client.py>
with the `method` argument to set the HTTP method (`GET`, `POST`, etc.),
but it's not working as expected: It always sends a POST request. If I
don't supply the `method` argument it always sends a GET request.

Application code:

    Client.call(
        'http://...',
        username = 'jdoe',
        password = 'mypw',
        method = 'GET')

I've traced it a bit in Client.py:

    def call(url,username=None, password=None, **kw):
        return apply(Function(url,username=username, password=password), (), kw)

OK, so `kw = { 'method': 'GET' }`. As far as I can tell this translates
to

    Function.__init__(
        'http://...',
        username = 'jdoe',
        password = 'mypw'
    ).__call__(
        method = 'GET')

`Function.__init__` expects `method` as part of its arguments but it's
not passed there:

        def __init__(self,url,
                     arguments=(),method=None,username=None,password=None,
                     timeout=None,
                     **headers):
            ...
            if method is not None: self.method=method

`Function.__call__` expects `method` to be set already:

        def __call__(self,*args,**kw):
            method=self.method

Should `call`'s signature and the `apply` call be modified to fit
`__init__`, or am I misunderstanding something? If it's really an error,
here's a proposed patch (Works For Me™):

    --- Client.py.orig
    +++ Client.py
    @@ -271,9 +271,9 @@
     
             return f
     
    -def call(url,username=None, password=None, **kw):
    +def call(url, arguments=(), method=None, username=None, password=None, timeout=None, **kw):
     
    -    return apply(Function(url,username=username, password=password), (), kw)
    +    return apply(Function(url, arguments=arguments, method=method, username=username, password=password, timeout=timeout), (), kw)
     
     ##############################################################################
     # Implementation details below here

** Affects: zope2
     Importance: Undecided
         Status: New


** Tags: http method

-- 
You received this bug notification because you are a member of Zope 2
Developers, which is subscribed to Zope 2.
https://bugs.launchpad.net/bugs/1152193

Title:
  ZPublisher.Client.call discards HTTP method argument

To manage notifications about this bug go to:
https://bugs.launchpad.net/zope2/+bug/1152193/+subscriptions


More information about the zope2-tracker mailing list