0

我正在使用以下脚本连接到 API。我确信细节很好(当我将这些细节与 Postman 一起使用时,它可以工作)。运行此代码时出现错误。我正在尝试连接到OpsGenie Heartbeat。奇怪的是,它每次都来自邮递员,但从不来自代码。

import http.client
headers = {"Content-type": "application/json", "Authorization": "Value"}
def connect():
    url = "<completeurl>"
    conn = http.client.HTTPConnection(url)
    conn.request("GET", "<apiurl>", {}, headers)
    print(http.client.responses)
    conn.close()

connect()

错误:

/home/fahad/PycharmProjects/Lambda2OpsGenie/venv/bin/python /home/fahad/PycharmProjects/Lambda2OpsGenie/lambda_function.py
{<HTTPStatus.PRECONDITION_REQUIRED: 428>: 'Precondition Required', <HTTPStatus.TOO_MANY_REQUESTS: 429>: 'Too Many Requests', <HTTPStatus.BAD_REQUEST: 400>: 'Bad Request', <HTTPStatus.UNAUTHORIZED: 401>: 'Unauthorized', <HTTPStatus.PAYMENT_REQUIRED: 402>: 'Payment Required', <HTTPStatus.FORBIDDEN: 403>: 'Forbidden', <HTTPStatus.NOT_FOUND: 404>: 'Not Found', <HTTPStatus.METHOD_NOT_ALLOWED: 405>: 'Method Not Allowed', <HTTPStatus.NOT_ACCEPTABLE: 406>: 'Not Acceptable', <HTTPStatus.PROXY_AUTHENTICATION_REQUIRED: 407>: 'Proxy Authentication Required', <HTTPStatus.REQUEST_TIMEOUT: 408>: 'Request Timeout', <HTTPStatus.CONFLICT: 409>: 'Conflict', <HTTPStatus.GONE: 410>: 'Gone', <HTTPStatus.LENGTH_REQUIRED: 411>: 'Length Required', <HTTPStatus.PRECONDITION_FAILED: 412>: 'Precondition Failed', <HTTPStatus.REQUEST_ENTITY_TOO_LARGE: 413>: 'Request Entity Too Large', <HTTPStatus.REQUEST_URI_TOO_LONG: 414>: 'Request-URI Too Long', <HTTPStatus.UNSUPPORTED_MEDIA_TYPE: 415>: 'Unsupported Media Type', <HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE: 416>: 'Requested Range Not Satisfiable', <HTTPStatus.EXPECTATION_FAILED: 417>: 'Expectation Failed', <HTTPStatus.UNPROCESSABLE_ENTITY: 422>: 'Unprocessable Entity', <HTTPStatus.LOCKED: 423>: 'Locked', <HTTPStatus.FAILED_DEPENDENCY: 424>: 'Failed Dependency', <HTTPStatus.UPGRADE_REQUIRED: 426>: 'Upgrade Required', <HTTPStatus.MULTIPLE_CHOICES: 300>: 'Multiple Choices', <HTTPStatus.MOVED_PERMANENTLY: 301>: 'Moved Permanently', <HTTPStatus.FOUND: 302>: 'Found', <HTTPStatus.SEE_OTHER: 303>: 'See Other', <HTTPStatus.NOT_MODIFIED: 304>: 'Not Modified', <HTTPStatus.USE_PROXY: 305>: 'Use Proxy', <HTTPStatus.TEMPORARY_REDIRECT: 307>: 'Temporary Redirect', <HTTPStatus.PERMANENT_REDIRECT: 308>: 'Permanent Redirect', <HTTPStatus.OK: 200>: 'OK'Too Many Requests, <HTTPStatus.CREATED: 201>: 'Created', <HTTPStatus.ACCEPTED: 202>: 'Accepted', <HTTPStatus.NON_AUTHORITATIVE_INFORMATION: 203>: 'Non-Authoritative Information', <HTTPStatus.NO_CONTENT: 204>: 'No Content', <HTTPStatus.RESET_CONTENT: 205>: 'Reset Content', <HTTPStatus.PARTIAL_CONTENT: 206>: 'Partial Content', <HTTPStatus.MULTI_STATUS: 207>: 'Multi-Status', <HTTPStatus.ALREADY_REPORTED: 208>: 'Already Reported', <HTTPStatus.IM_USED: 226>: 'IM Used', <HTTPStatus.CONTINUE: 100>: 'Continue', <HTTPStatus.SWITCHING_PROTOCOLS: 101>: 'Switching Protocols', <HTTPStatus.PROCESSING: 102>: 'Processing', <HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE: 431>: 'Request Header Fields Too Large', <HTTPStatus.INTERNAL_SERVER_ERROR: 500>: 'Internal Server Error', <HTTPStatus.NOT_IMPLEMENTED: 501>: 'Not Implemented', <HTTPStatus.BAD_GATEWAY: 502>: 'Bad Gateway', <HTTPStatus.SERVICE_UNAVAILABLE: 503>: 'Service Unavailable', <HTTPStatus.GATEWAY_TIMEOUT: 504>: 'Gateway Timeout', <HTTPStatus.HTTP_VERSION_NOT_SUPPORTED: 505>: 'HTTP Version Not Supported', <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'}

Process finished with exit code 0
4

0 回答 0