Skip to content

Commit 2d27d73

Browse files
authored
Merge pull request #117 from kurusugawa-computer/bugfix-parse-content-type
Content-Typeが`application/json;charset=utf-8`のときでも、正しく認識できるようにする
2 parents 5647169 + 9aac82f commit 2d27d73

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

annofabapi/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.25.1'
1+
__version__ = '0.25.2'

annofabapi/api.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,14 @@ def _response_to_content(response: requests.Response) -> Any:
157157
"""
158158

159159
content_type = response.headers['Content-Type']
160-
if content_type == 'application/json':
160+
# `Content-Type: application/json;charset=utf-8`などcharsetが含まれている場合にも対応できるようにする。
161+
tokens = content_type.split(';')
162+
media_type = tokens[0].strip()
163+
164+
if media_type == 'application/json':
161165
content = response.json() if len(response.content) != 0 else {}
162166

163-
elif content_type.find('text/') >= 0:
167+
elif media_type.find('text/') >= 0:
164168
content = response.text
165169

166170
else:

0 commit comments

Comments
 (0)