python 状态码转字典文本_url请求返回状态码与状态内容 (in python)

web自动化测试的时候,我们常常要进行整站几个重要的url的可用性测试,下面就是一个比较全面的url返回码与对应内容的list.

StatusCode = {

100: ('Continue', 'Request received, please continue'),

101: ('Switching Protocols',

'Switching to new protocol; obey Upgrade header'),

200: ('OK', 'Request fulfilled, document follows'),

201: ('Created', 'Document created, URL follows'),

202: ('Accepted',

'Request accepted, processing continues off-line'),

203: ('Non-Authoritative Information', 'Request fulfilled from cache'),

204: ('No Content', 'Request fulfilled, nothing follows'),

205: ('Reset Content', 'Clear input form for further input.'),

206: ('Partial Content', 'Partial content follows.'),

300: ('Multiple Choices',

'Object has several resources -- see URI list'),

301: ('Moved Permanently', 'Object moved permanently -- see URI list'),

302: ('Found', 'Object moved temporarily -- see URI list'),

303: ('See Other', 'Object moved -- see Method and URL list'),

304: ('Not Modified',

'Document has not changed since given time'),

305: ('Use Proxy',

'You must use proxy specified in Location to access this '

'resource.'),

307: ('Temporary Redirect',

'Object moved temporarily -- see URI list'),

400: ('Bad Request',

'Bad request syntax or unsupported method'),

401: ('Unauthorized',

'No permission -- see authorization schemes'),

402: ('Payment Required',

'No payment -- see charging schemes'),

403: ('Forbidden',

'Request forbidden -- authorization will not help'),

404: ('Not Found', 'Nothing matches the given URI'),

405: ('Method Not Allowed',

'Specified method is invalid for this server.'),

406: ('Not Acceptable', 'URI not available in preferred format.'),

407: ('Proxy Authentication Required', 'You must authenticate with '

'this proxy before proceeding.'),

408: ('Request Timeout', 'Request timed out; try again later.'),

409: ('Conflict', 'Request conflict.'),

410: ('Gone',

'URI no longer exists and has been permanently removed.'),

411: ('Length Required', 'Client must specify Content-Length.'),

412: ('Precondition Failed', 'Precondition in headers is false.'),

413: ('Request Entity Too Large', 'Entity is too large.'),

414: ('Request-URI Too Long', 'URI is too long.'),

415: ('Unsupported Media Type', 'Entity body in unsupported format.'),

416: ('Requested Range Not Satisfiable',

'Cannot satisfy request range.'),

417: ('Expectation Failed',

'Expect condition could not be satisfied.'),

500: ('Internal Server Error', 'Server got itself in trouble'),

501: ('Not Implemented',

'Server does not support this operation'),

502: ('Bad Gateway', 'Invalid responses from another server/proxy.'),

503: ('Service Unavailable',

'The server cannot process the request due to a high load'),

504: ('Gateway Timeout',

'The gateway server did not receive a timely response'),

505: ('HTTP Version Not Supported', 'Cannot fulfill request.')

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在 Python 发送 HTTP POST 请求可以使用内置的 `requests` 库。 下面是一个简单的例子: ``` import requests url = "https://www.example.com/api/create_user" data = {"username": "test_user", "email": "test_user@example.com"} response = requests.post(url, data=data) print(response.status_code) print(response.text) ``` 在上面的代码,我们首先导入了 `requests` 库,然后定义了我们要请求URL 和要发送的数据。接下来,我们使用 `requests.post` 函数发送了一个 POST 请求,并将响应存储在 `response` 变量。最后,我们输出了响应的 HTTP 状态码和响应的文本内容。 ### 回答2: 在Python,使用`requests`库可以很方便地发送POST请求。首先,你需要安装`requests`库,可以通过以下命令在命令行安装: ``` pip install requests ``` 安装完成后,在Python脚本引入`requests`库: ```python import requests ``` 接下来,你可以使用`requests.post()`方法来发送POST请求。此方法接受一个URL作为参数,并可以传递其他参数,如请求头、请求体等。下面是一个例子: ```python import requests # 定义请求URL url = "http://example.com/post" # 定义请求的数据(可以是字典、字符串等) data = {"key1": "value1", "key2": "value2"} # 发送POST请求 response = requests.post(url, data=data) # 获取响应结果 print(response.text) ``` 在这个例子,我们定义了一个URL和一个字典作为请求的数据。`requests.post()`方法发送了一个POST请求,并返回一个`Response`对象。我们可以通过`response.text`属性获取响应结果,并将其打印出来。 除了传递数据,你还可以传递其他参数,例如请求头、请求体格式等。`requests.post()`方法还可以接受`headers`参数、`json`参数等。你可以根据具体需要进行设置。 需要注意的是,如果你的POST请求需要认证或者使用HTTPS协议,可能需要额外的配置。你可以查阅`requests`库的官方文档以获取更详细的信息。 ### 回答3: 在Python进行post请求有多种方式,以下是其一种常见的方法: 首先,我们需要使用Python的`requests`库来发送HTTP请求。如果你还没有安装该库,可以使用以下命令进行安装: ``` pip install requests ``` 然后,我们可以使用`requests`库的`post`方法来发送post请求。该方法接收两个参数:请求URL请求的参数。下面是一个示例: ```python import requests # 请求URL url = 'https://example.com/api/endpoint' # 请求的参数 params = { 'param1': 'value1', 'param2': 'value2' } # 发送post请求 response = requests.post(url, data=params) # 获取响应结果 result = response.text # 打印响应结果 print(result) ``` 在上面的示例,我们首先定义了请求URL请求的参数。然后,使用`requests.post`方法发送POST请求,并将响应结果保存在`response`变量。最后,我们通过`response.text`属性获取响应结果,并打印出来。 需要注意的是,如果需要发送JSON格式的数据,可以将`data`参数改为`json`参数,并将参数数据换为JSON格式。示例代码如下: ```python import requests import json # 请求URL url = 'https://example.com/api/endpoint' # 请求的参数 params = { 'param1': 'value1', 'param2': 'value2' } # 将参数换为JSON格式 data_json = json.dumps(params) # 发送post请求 response = requests.post(url, json=data_json) ... ``` 希望以上回答能对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值