8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PythonのRequestsのステータスコード

Last updated at Posted at 2019-11-09

RequestsでHTTPリクエストを送ったあと、そのレスポンスのステータスコードを確認することはよくある。

import requests

response = requests.get(...)

assert response.status_code == 200

などである。
しかし、このときRequestsの定数を用いて、

assert response.status_code == requests.codes.ok

などと書くことができる。
こうすることで、200というマジックナンバー使わずに済む。

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?