我目前正在使用CSGO Gamestate Integration(Info Here)来收集数据。本质上,我启动了HTTP服务器来处理游戏中的POST请求。我需要的是从其他Python脚本发送POST请求,以将数据与我正在执行的另一操作同步。基本上,只需要服务器识别它已接收到数据包,但我收到了HTTP错误。
HTTP Server POST方法的代码:
def do_POST(self):
length = int(self.headers['Content-Length'])
body = self.rfile.read(length).decode('utf-8')
print(pprint.pprint(self.responses))
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.parse_frameSync_payload(json.loads(body))
请求POST代码:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36'}
try:
r = requests.post('http://127.0.0.1:3000', json={'auth': 'frameSync'}, headers=headers)
print(r.status_code)
except requests.exceptions.ConnectTimeout:
print(r.status_code, r.reason)
print('frameSync: \t\tConnection Refused.')
运行请求时HTTP Server的输出:
{<HTTPStatus.CONTINUE: 100>: ('Continue', 'Request received, please continue'),
<HTTPStatus.SWITCHING_PROTOCOLS: 101>: ('Switching Protocols',
'Switching to new protocol; obey '
'Upgrade header'),
<HTTPStatus.PROCESSING: 102>: ('Processing', ''),
<HTTPStatus.OK: 200>: ('OK', 'Request fulfilled, document follows'),
<HTTPStatus.CREATED: 201>: ('Created', 'Document created, URL follows'),
<HTTPStatus.ACCEPTED: 202>: ('Accepted',
'Request accepted, processing continues '
'off-line'),
<HTTPStatus.NON_AUTHORITATIVE_INFORMATION: 203>: ('Non-Authoritative '
'Information',
'Request fulfilled from '
'cache'),
<HTTPStatus.NO_CONTENT: 204>: ('No Content',
'Request fulfilled, nothing follows'),
<HTTPStatus.RESET_CONTENT: 205>: ('Reset Content',
'Clear input form for further input'),
<HTTPStatus.PARTIAL_CONTENT: 206>: ('Partial Content',
'Partial content follows'),
<HTTPStatus.MULTI_STATUS: 207>: ('Multi-Status', ''),
<HTTPStatus.ALREADY_REPORTED: 208>: ('Already Reported', ''),
<HTTPStatus.IM_USED: 226>: ('IM Used', ''),
<HTTPStatus.MULTIPLE_CHOICES: 300>: ('Multiple Choices',
'Object has several resources -- see URI '
'list'),
<HTTPStatus.MOVED_PERMANENTLY: 301>: ('Moved Permanently',
'Object moved permanently -- see URI '
'list'),
<HTTPStatus.FOUND: 302>: ('Found', 'Object moved temporarily -- see URI list'),
<HTTPStatus.SEE_OTHER: 303>: ('See Other',
'Object moved -- see Method and URL list'),
<HTTPStatus.NOT_MODIFIED: 304>: ('Not Modified',
'Document has not changed since given time'),
<HTTPStatus.USE_PROXY: 305>: ('Use Proxy',
'You must use proxy specified in Location to '
'access this resource'),
<HTTPStatus.TEMPORARY_REDIRECT: 307>: ('Temporary Redirect',
'Object moved temporarily -- see URI '
'list'),
<HTTPStatus.PERMANENT_REDIRECT: 308>: ('Permanent Redirect',
'Object moved temporarily -- see URI '
'list'),
<HTTPStatus.BAD_REQUEST: 400>: ('Bad Request',
'Bad request syntax or unsupported method'),
<HTTPStatus.UNAUTHORIZED: 401>: ('Unauthorized',
'No permission -- see authorization schemes'),
<HTTPStatus.PAYMENT_REQUIRED: 402>: ('Payment Required',
'No payment -- see charging schemes'),
<HTTPStatus.FORBIDDEN: 403>: ('Forbidden',
'Request forbidden -- authorization will not '
'help'),
<HTTPStatus.NOT_FOUND: 404>: ('Not Found', 'Nothing matches the given URI'),
<HTTPStatus.METHOD_NOT_ALLOWED: 405>: ('Method Not Allowed',
'Specified method is invalid for this '
'resource'),
<HTTPStatus.NOT_ACCEPTABLE: 406>: ('Not Acceptable',
'URI not available in preferred format'),
<HTTPStatus.PROXY_AUTHENTICATION_REQUIRED: 407>: ('Proxy Authentication '
'Required',
'You must authenticate with '
'this proxy before '
'proceeding'),
<HTTPStatus.REQUEST_TIMEOUT: 408>: ('Request Timeout',
'Request timed out; try again later'),
<HTTPStatus.CONFLICT: 409>: ('Conflict', 'Request conflict'),
<HTTPStatus.GONE: 410>: ('Gone',
'URI no longer exists and has been permanently '
'removed'),
<HTTPStatus.LENGTH_REQUIRED: 411>: ('Length Required',
'Client must specify Content-Length'),
<HTTPStatus.PRECONDITION_FAILED: 412>: ('Precondition Failed',
'Precondition in headers is false'),
<HTTPStatus.REQUEST_ENTITY_TOO_LARGE: 413>: ('Request Entity Too Large',
'Entity is too large'),
<HTTPStatus.REQUEST_URI_TOO_LONG: 414>: ('Request-URI Too Long',
'URI is too long'),
<HTTPStatus.UNSUPPORTED_MEDIA_TYPE: 415>: ('Unsupported Media Type',
'Entity body in unsupported '
'format'),
<HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE: 416>: ('Requested Range Not '
'Satisfiable',
'Cannot satisfy request '
'range'),
<HTTPStatus.EXPECTATION_FAILED: 417>: ('Expectation Failed',
'Expect condition could not be '
'satisfied'),
<HTTPStatus.UNPROCESSABLE_ENTITY: 422>: ('Unprocessable Entity', ''),
<HTTPStatus.LOCKED: 423>: ('Locked', ''),
<HTTPStatus.FAILED_DEPENDENCY: 424>: ('Failed Dependency', ''),
<HTTPStatus.UPGRADE_REQUIRED: 426>: ('Upgrade Required', ''),
<HTTPStatus.PRECONDITION_REQUIRED: 428>: ('Precondition Required',
'The origin server requires the '
'request to be conditional'),
<HTTPStatus.TOO_MANY_REQUESTS: 429>: ('Too Many Requests',
'The user has sent too many requests in '
'a given amount of time ("rate '
'limiting")'),
<HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE: 431>: ('Request Header Fields '
'Too Large',
'The server is unwilling '
'to process the request '
'because its header '
'fields are too large'),
<HTTPStatus.INTERNAL_SERVER_ERROR: 500>: ('Internal Server Error',
'Server got itself in trouble'),
<HTTPStatus.NOT_IMPLEMENTED: 501>: ('Not Implemented',
'Server does not support this operation'),
<HTTPStatus.BAD_GATEWAY: 502>: ('Bad Gateway',
'Invalid responses from another server/proxy'),
<HTTPStatus.SERVICE_UNAVAILABLE: 503>: ('Service Unavailable',
'The server cannot process the '
'request due to a high load'),
<HTTPStatus.GATEWAY_TIMEOUT: 504>: ('Gateway Timeout',
'The gateway server did not receive a '
'timely response'),
<HTTPStatus.HTTP_VERSION_NOT_SUPPORTED: 505>: ('HTTP Version Not Supported',
'Cannot fulfill request'),
<HTTPStatus.VARIANT_ALSO_NEGOTIATES: 506>: ('Variant Also Negotiates', ''),
<HTTPStatus.INSUFFICIENT_STORAGE: 507>: ('Insufficient Storage', ''),
<HTTPStatus.LOOP_DETECTED: 508>: ('Loop Detected', ''),
<HTTPStatus.NOT_EXTENDED: 510>: ('Not Extended', ''),
<HTTPStatus.NETWORK_AUTHENTICATION_REQUIRED: 511>: ('Network Authentication '
'Required',
'The client needs to '
'authenticate to gain '
'network access')}