A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/cztomczak/cefpython/issues/517 below:

Request.GetPostData() throws UnicodeEncodeError · Issue #517 · cztomczak/cefpython · GitHub

Here is the faulty code:

retUrlEncoded.update(urlparse.parse_qsl(qs=pyData,

It occurs only when content-type is "application/x-www-form-urlencoded". urllib.parse.parse_qsl requires str data instead of bytes when data contains non-ascii character.

Reported on the Forum:
https://groups.google.com/d/topic/cefpython/A7gDz3XmK1I/discussion

Code to reproduce the problem:

# coding=utf8
from cefpython3 import cefpython as cef
import sys

html = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
  window.onload = function() {
   fetch('http://127.0.0.1:8000', {
       method: 'POST',
       headers: {'Content-Type': 'application/x-www-form-urlencoded'},
       body: 'key=' + encodeURI('🍣'),
   }).then().catch();
  }
</script>
</body>
</html>
"""


class RequestHandler:
    def GetResourceHandler(self, browser, frame, request):
        print(request.GetPostData())
        return None

def main():
    sys.excepthook = cef.ExceptHook
    cef.Initialize()
    browser = cef.CreateBrowserSync(url=cef.GetDataUrl(html))
    browser.SetClientHandler(RequestHandler())
    cef.MessageLoop()
    del browser
    cef.Shutdown()


if __name__ == '__main__':
    main()

Error and traceback:

Traceback (most recent call last):
  File "request_handler.pyx", line 150, in cefpython_py37.RequestHandler_GetResourceHandler
  File "/Volumes/SSD-PLU3/Users/*****/Library/Preferences/PyCharm2018.3/scratches/getpost.py", line 28, in GetResourceHandler
    print(request.GetPostData())
  File "request.pyx", line 83, in cefpython_py37.PyRequest.GetPostData
  File "request.pyx", line 122, in cefpython_py37.PyRequest.GetPostData
  File "/Users/******/.pyenv/versions/3.7.2/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 720, in parse_qsl
    value = _coerce_result(value)
  File "/Users/******/.pyenv/versions/3.7.2/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 103, in _encode_result
    return obj.encode(encoding, errors)
UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f363' in position 0: ordinal not in range(128)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4