0

I am using Python soap API client Zeep and here is the code that I have written:

from zeep import Client

def myapi(request):
    client = Client("https://siteURL.asmx?wsdl")
    key = client.service.LogOnUser('myusername', 'mypassord')
    print(key)

it is giving me an error as: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

While I am trying below command the URL works well and shows all the services it has

python -mzeep https://siteURL.asmx?wsdl

Please help to understand what is the reason above code is not working.

PS: I couldn't share site URL which I am trying to connect to.

Additional Info: The site/page is accessible only through intranet and I am testing locally from intranet itself.

Traceback error:

Exception Type: ConnectionError at /music/mypersonalapi/
Exception Value: HTTPSConnectionPool(host='URL I have hidden', port=81): 
Max retries exceeded with url: /ABC/XYZ/Logon.asmx
(Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0546E770>: 
Failed to establish a new connection:
[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))

Please note: I have removed URL and Host information from my traceback due to confidentiality

Cнιяαg
  • 11
  • 2
  • I think you've made at least a couple of copy-paste errors in your sample code (`client` vs `my_client`, `Key: " & key`), you've also forgotten to include the traceback.. – thebjorn Aug 30 '18 at 12:02
  • Thanks for checking... but I did use client... it was giving an issue. didn't understand what you mean by traceback. – Cнιяαg Aug 30 '18 at 13:01
  • The traceback is the messages Python prints when it gives you the error. Look at the bottom of this question for an example: https://stackoverflow.com/questions/4761874/what-is-the-meaning-of-the-traceback (this tells you where the error happened and what happened just prior to it). – thebjorn Aug 30 '18 at 16:06
  • Here is what traceback last line shows: Exception Type: ConnectionError at /music/mypersonalapi/ Exception Value: HTTPSConnectionPool(host='URL I have hidden', port=81): Max retries exceeded with url: /ABC/XYZ/Logon.asmx (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',)) – Cнιяαg Aug 31 '18 at 10:10
  • Please update your question (it's relevant to the question and comments lose all formatting). – thebjorn Aug 31 '18 at 10:16
  • I think the issue is... server is not able to understand that request is coming from local system only or another issue could be script not able to pass info in "https"? – Cнιяαg Aug 31 '18 at 10:32
  • "The site/page is accessible only through intranet" Could you try http instead of https. I suspect 'lack of cookie bag' problems, which http wouldn't be effected by. – Davesoft Aug 31 '18 at 10:39
  • Thanks for replying: If i do python -mzeep http://siteURL.asmx?wsdl (with http instead of https it doesn't return anything, it works with https only) – Cнιяαg Aug 31 '18 at 10:42
  • Not sure if this will help, we had similar issue in .net code and we were able to fix by adding one line that was: binding.Security.Mode = BasicHttpSecurityMode.Transport; is there anything similar in python we can do? – Cнιяαg Aug 31 '18 at 10:44

2 Answers2

4

What this does:

python -mzeep https://site/url.asmx?wsdl

is:

c = Client("https://site/url.asmx?wsdl")
c.wsdl.dump()

both alternatives are using port 443 since that is the default https port.

From your traceback we see

Exception Value: HTTPSConnectionPool(host='URL I have hidden', port=81): 

which would have been similar to

python -mzeep https://site:81/url.asmx?wsdl

I.e. the command line and your code are not connecting to the same address (also note that port values less than 1024 requires system level permissions to use -- in case you're writing/controlling the service too).

The last line does say "..failed because the connected party did not properly respond after a period of time..", but that is not the underlying reason. In line 3 you can read

Max retries exceeded with url: /ABC/XYZ/Logon.asmx

in other words, you've tried (and failed) to log on too many times and the server is probably doubling the time it uses to respond every time you try (a well known mitigation strategy for "things" that fail to login multiple times -- i.e. look like an attack). The extended delay is most likely causing the error message you see at the bottom.

You'll need to wait a while, or reset your account for the service, and if the service is yours then perhaps turn off this feature during development?

thebjorn
  • 26,297
  • 11
  • 96
  • 138
  • Thank you so much for looking into this and in-depth explanation of each of the lines. – Cнιяαg Sep 01 '18 at 19:25
  • You're very welcome. If my answer was helpful please click the up-arrow at the top of the answer, and if it answered your question then please click the checkmark below the up/down arrows. This will help people who find this question and answer in the future see what worked (and it will give me virtual points ;-) – thebjorn Sep 01 '18 at 20:11
  • I tried doing up-arrow, it seems I am very new (less than 15 rep) hence its not allowing me to up arrow. – Cнιяαg Sep 03 '18 at 11:58
0

Maybe this can help. I had the same connexion problem (Max retries exceeded...). I solved it by increasing the transport timeout.

client = Client(wsdl=wsdl, transport=Transport(session=session, timeout=120))
Hbon
  • 1
  • 1