2

Trying to get data from a URL, But having trouble with the request. I assume its something to do with the formatting ( there is none ) of the page or data?

I am using Python 3.6.5, requests 2.20.0

import requests
r = requests.get('http://37.187.88.24:7141/')
print (r)

It gives me this error and showing the first line of the page

File " ..  \Python36-32\lib\http\client.py", line 279, in _read_statusraise BadStatusLine(line)http.client.BadStatusLine: <ServerStats>
1
  • 1
    Try updating requests, urllib3. pip install urllib3 Commented Oct 26, 2018 at 1:53

1 Answer 1

2

The response from that server simply does not follow the HTTP protocol. It responds with the content directly without a status line (usually a HTTP/1.1 200 OK). You can see this with a utility like curl:

# curl -v http://37.187.88.24:7141/
*   Trying 37.187.88.24...
* TCP_NODELAY set
* Connected to 37.187.88.24 (37.187.88.24) port 7141 (#0)
> GET / HTTP/1.1
> Host: 37.187.88.24:7141
> User-Agent: curl/7.56.1
> Accept: */*
>
<ServerStats>
<Name>TP_Map_Test</Name>
<ModuleName>Napoleonic Wars</ModuleName>
...(snipped)

If you own that web server, fix your web app to give a valid response. If you don't, you can use telnetlib to communicate with the server via the underlying telnet protocol instead:

from telnetlib import Telnet
t = Telnet('37.187.88.24', 7141)
t.write(b'GET / HTTP/1.0\n')
print(t.read_all())

This outputs:

b'<ServerStats>\n<Name>TP_Map_Test</Name>\n<ModuleName>Napoleonic Wars</ModuleName>\n<MultiplayerVersionNo>1157</MultiplayerVersionNo>\n<ModuleVersionNo>1210</ModuleVersionNo>\n<MapID>162</MapID>\n<MapName>custom map 1</MapName>\n<MapTypeID>4</MapTypeID>\n<MapTypeName>Deathmatch</MapTypeName>\n<NumberOfActivePlayers>0</NumberOfActivePlayers>\n<MaxNumberOfPlayers>4</MaxNumberOfPlayers>\n<HasPassword>Yes</HasPassword>\n<IsDedicated>Yes</IsDedicated>\n<HasSteamAntiCheat>No</HasSteamAntiCheat>\n<ModuleSetting0>6</ModuleSetting0>\n<ModuleSetting1>8</ModuleSetting1>\n<ModuleSetting2>0</ModuleSetting2>\n<ModuleSetting3>0</ModuleSetting3>\n<ModuleSetting4>1</ModuleSetting4>\n<ModuleSetting5>1</ModuleSetting5>\n<ModuleSetting6>100</ModuleSetting6>\n<ModuleSetting7>0</ModuleSetting7>\n<ModuleSetting8>0</ModuleSetting8>\n<ModuleSetting9>1</ModuleSetting9>\n<ModuleSetting10>2</ModuleSetting10>\n<ModuleSetting11>120</ModuleSetting11>\n<ModuleSetting12>300</ModuleSetting12>\n<ModuleSetting13>5</ModuleSetting13>\n</ServerStats>'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.