From fc07a4ae4a3be6611f35a03ab7cd27ccb15b235a Mon Sep 17 00:00:00 2001 From: dem4ply Date: Thu, 11 Oct 2018 16:13:59 -0500 Subject: [PATCH] add utf-8 when is using a post --- mudskipper/endpoint.py | 2 ++ tests/endpoint.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/mudskipper/endpoint.py b/mudskipper/endpoint.py index 81d048b..e6063f2 100644 --- a/mudskipper/endpoint.py +++ b/mudskipper/endpoint.py @@ -100,6 +100,8 @@ def generate_post_headers( self ): return None def post( self, body=None ): + if isinstance( body, str ): + body = body.encode( 'UTF-8' ) headers = self.generate_post_headers() response = requests.post( self.format_url, data=body, headers=headers, diff --git a/tests/endpoint.py b/tests/endpoint.py index c3044b9..9cb417e 100644 --- a/tests/endpoint.py +++ b/tests/endpoint.py @@ -82,6 +82,11 @@ def test_should_change_the_url( self ): new_endpoint.format_url, 'http://a.4cdn.org/w/threads.json' ) +class Test_utf_8( Test_endpoint_4chan_thread, Test_format, Test_init ): + def test_should_work( self ): + self.endpoint.format( board='w' ).post( body='’' ) + + class Test_instance( Test_endpoint_4chan_thread, Test_format, Test_init ): pass