Server returned HTTP response code: 405 for URL: https://www.google.com
I can take the output e and parse it (or sledge it with a regex), but before I start messing with strings, I figured I’d check if I just missed an obvious way to just extract the HTTP status code. Thanks!
Here’s a playground script of what I was thinking:
[code]import re
pattern = ‘HTTP response code: ([0-9]{3}) for URL: (http[s]?://.*)’
source = ‘Server returned HTTP response code: 405 for URL: https://www.google.com’
regex = re.compile(pattern)
match = regex.findall(source)
for m in match:
print m[/code]
yielding
('405', 'https://www.google.com')
It’ll work, but I can’t help but feel it’s a bit heavy-handed for the job. I could just do some string splicing, but I don’t know if I should count on the string being perfectly identically formatted for all errors.
Does one approach have any significant advantages?
Getting SSL to work right without calling upon Java is hard (possible in Jython 2.5.3?), so I figured it would be more reliable to use the built-in function. I also guessed there may be some nice side effects, like Ignition handling some connection pooling or the like. And it’s somewhat turn-key (except for error handling, which is going to be non-optimal anyway).
But since I’ll be making quite a few HTTP requests regularly, it wouldn’t be a terrible idea to optimize this early.