from httprunner import HttpRunner, Config, Step, RunRequest class TestCaseGetToken(HttpRunner): config = Config("testcase description") teststeps = [ Step( RunRequest("/cgi-bin/token") .get("https://api.weixin.qq.com/cgi-bin/token") .with_params( **{ "appid": "wxba9a30b144d1fd16", "grant_type": "client_credential", "secret": "6a0b75e631ebe43f6d60a551ad4ac3fe", } ) .with_headers( **{ "Postman-Token": "9250a585-9ce0-4ffb-a62b-de0d87adde4a", "User-Agent": "PostmanRuntime/7.32.2", } ) .validate() .assert_equal("status_code", 200) .assert_equal('headers."Content-Type"', "application/json; encoding=utf-8") ), ] if __name__ == "__main__": TestCaseGetToken().test_start() 代码中如何添加verify=False
时间: 2024-02-14 10:23:37 浏览: 137
你可以在发送请求的时候,在 `get()` 方法或者 `post()` 方法中添加 `verify=False` 参数来关闭 SSL 认证。例如,在发送 GET 请求时,你可以这样修改代码:
```python
Step(
RunRequest("/cgi-bin/token")
.get("https://api.weixin.qq.com/cgi-bin/token", verify=False) # 添加 verify=False 参数
.with_params(
**{
"appid": "wxba9a30b144d1fd16",
"grant_type": "client_credential",
"secret": "6a0b75e631ebe43f6d60a551ad4ac3fe",
}
)
.with_headers(
**{
"Postman-Token": "9250a585-9ce0-4ffb-a62b-de0d87adde4a",
"User-Agent": "PostmanRuntime/7.32.2",
}
)
.validate()
.assert_equal("status_code", 200)
.assert_equal('headers."Content-Type"', "application/json; encoding=utf-8")
),
```
注意,在生产环境中关闭 SSL 认证是不安全的,因为这可能会导致你的应用程序容易受到中间人攻击。因此,我们建议在开发和测试环境中使用 `verify=False` 参数,但在生产环境中关闭它。
阅读全文