The Zurich release has arrived! Interested in new features and functionalities? Click here for more

PowerShell API "An unexpected error occurred on a send."

jeremy_01
Mega Contributor

Hello,

I scripted some powershell modules a few months ago, specifically right now, I'll say for incidents.   Back when I scripted them they were working flawlessly, obviously I was able to get all the response data back from the JSON.   As of a couple weeks ago, The scripts are failing and the only detail in the error is (PowerShell)

"The underlying connection was closed: An unexpected error occurred on a send."

My perl scripts using cURL failed as well unless I use the   -k   (ignore SSL Certficiates)

* TCP_NODELAY set

* Connected to service-now.com (xx.xx.xx.xxxx) port 443 (#0)

* ALPN, offering http/1.1

* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH

* TLSv1.2 (OUT), TLS header, Certificate Status (22):

} [5 bytes data]

* TLSv1.2 (OUT), TLS handshake, Client hello (1):

} [512 bytes data]

* TLSv1.2 (IN), TLS handshake, Server hello (2):

{ [99 bytes data]

* TLSv1.2 (IN), TLS handshake, Certificate (11):

{ [3943 bytes data]

* TLSv1.2 (OUT), TLS alert, Server hello (2):

} [2 bytes data]

* SSL certificate problem: unable to get local issuer certificate

* Closing connection 0

} [5 bytes data]

* TLSv1.2 (OUT), TLS alert, Client hello (1):

} [2 bytes data]

So, I've added this to my PowerShell scripts

try {

    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

    [System.Net.ServicePointManager]::MaxServicePointIdleTime = 10000

    $response = Invoke-WebRequest -Headers $headers -Method GET -ContentType "application/json" -Uri $uri

}

This doesn't seem to fix. I've reported the issue to the dev team, they've asked around and no one else seems to be impacted. Another user using PowerShell says they use retry logic and it works.   Which I tried, but unsuccessful. Also this seems to be inconsistent, the other day I ran my script, it didn't work. 5 minutes later the script worked (returned the incident information). Now its back to not working (throwing http error) and I haven't changed a darn thing in my script. I'm pretty frustrated at this point and I am hoping someone can shed some light on this. I would really appreciate any suggestions. Thank you.

1 ACCEPTED SOLUTION

jeremy_01
Mega Contributor

Problem solved, I updated the servicemanager protocol to Tls12 on my machine and the support team had to fix the connection timeout on the server side.


View solution in original post

1 REPLY 1

jeremy_01
Mega Contributor

Problem solved, I updated the servicemanager protocol to Tls12 on my machine and the support team had to fix the connection timeout on the server side.