diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index 47caad26d49..079b9e935d0 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -655,6 +655,7 @@ def __init__(self, obj, headers=None, *, chunk_size=8192): self._serialize_map = { bytes: self._serialize_bytes, str: self._serialize_str, + int: self._serialize_int, io.IOBase: self._serialize_io, MultipartWriter: self._serialize_multipart, ('application', 'json'): self._serialize_json, @@ -757,6 +758,9 @@ def _serialize_str(self, obj): *_, params = parse_mimetype(self.headers.get(CONTENT_TYPE)) yield obj.encode(params.get('charset', 'us-ascii')) + def _serialize_int(self, obj): + return self._serialize_str(str(obj)) + def _serialize_io(self, obj): while True: chunk = obj.read(self._chunk_size) diff --git a/tests/test_multipart.py b/tests/test_multipart.py index cb39656ad4d..ae1e1811e3b 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -772,6 +772,9 @@ def test_serialize_bytes(self): def test_serialize_str(self): self.assertEqual(b'foo', next(self.part._serialize_str('foo'))) + def test_serialize_int(self): + self.assertEqual(b'42', next(self.part._serialize_int(42))) + def test_serialize_str_custom_encoding(self): self.part.headers[CONTENT_TYPE] = \ 'text/plain;charset=cp1251'