httpGet calls to Kepware REST API - IOError: Unexpected end of file from server

I need some help with system.net.httpGet / Post

Background -
Ignition 7.9.10
Kepware 6.6.350.0

When I send the following
r = system.net.httpGet(“http://127.0.0.1:57412/config/v1/project/channels/ENU Tower/”,username=“XXXXXXXXXX”)

It returns - “IOError: Unexpected end of file from server”

however when I send
r = system.net.httpGet(“http://127.0.0.1:57412/config/v1/project/channels/",username="XXXXXXXXX”)

I get a valid response from Kepware.
Here’s the strange part… When I use Postman to send Get and Post calls everything works fine.
I can post the responses from Potman but excluded them for now as they are extremely lengthy.

Maybe you can spot the difference between Postman and the call that doesn’t work using Wireshark?

I was really trying to avoid packet capture…
I’ll fire up WireShark… Let you know what I find…

“IOError: Unexpected end of file from server” means the server (or something else) closed the connection for some reason. Since you can successfully make a request to a different URI it’s probably not something else, like a firewall or AV, and it’s KSE doing it for some reason.

If there were any logs to indicate why they’d be in KSE, not Ignition, so a packet capture seems like an easy next step.

Yep… Packet Capture Done…
Here’s what I found…
If I send with %20 in the spaces I get get a response…
system.net.httpGet(“http://127.0.0.1:57412/config/v1/project/channels/ENU%20Tower/devices/Testing%20The%20API/meter_groups/",username="XXX”)

If I send with spaces I get the error…
system.net.httpGet(“http://127.0.0.1:57412/config/v1/project/channels/ENU Tower/devices/Testing The API/meter_groups/”,username=“XXX”)

ARG

Not a huge deal I can just run replace(" “,”%20") on my url strings before passing them into the argument.

You might be able to use python’s urlencode function: https://docs.python.org/2/library/urllib.html#urllib.urlencode

You’ll have to see if it’s actually part of the version of Jython we ship though.

1 Like

I was kinda expecting the function call to format the url properly?
The doc just says to pass it a url…
All though the second code snippet does have the %20 in the url…

Any chance we could have it put in as a bug…
Honestly I’m surprised no one else has ever had this issue…
Must not be a commonly used function. - Or I’m just a moron

It’s very commonly used, but spaces in URLs are less common I guess.

and FWIW, a string with spaces in it is not technically a URL, because URLs cannot contain spaces.

Confirmed - Moron Status… :stuck_out_tongue_winking_eye:

I do think it would be nice if it URL-encoded things for you… but then if someone passed an already encoded / proper URL, it would get double-encoded…

Right…

Well thanks for the help Kevin…