سؤال

I am using the suds package to make API request from one website. I wrote a function which opens up the client to the website and make request.

I am wondering should I or how can I terminate the connection in the end of the function?

I am wondering will the client be something like the MySQLDb.connect that actually opens up many many separate API connections that never close every time I call this function.

from suds.client import Client
import sys, re

def querysearch(reqPartNumber, reqMfg, lock):
    try:
        client = Client('http://app....')
        userInfo = {'id':.., 'password':...}
        apiResponse = client.service.getParts(...)
        ...
        print apiResponse
    except:
        ...
هل كانت مفيدة؟

المحلول

SOAP is still an HTTP request, which is stateless. Each request will start a whole new connection, re-auth, etc. Browsers kind of short circuit that with cookies, but SOAP doesn't. So, you don't need to close the connection, it's already closed by the time suds returns your data back to you.

Additionally, looking at the latest source, Client() doesn't define a close or __exit__ method, so there's nothing you really have to do here.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top