Python Forum

Full Version: TypeError: sequence of byte string values expected, value of type str found
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to get mod_wsgi up and running but when I try to open a test page with the following code I get the error saying that a byte string is expected

def application(environ,start_response):
    status = '200 OK'
    html = '<html>\n' \
           '<body>\n' \
           '<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">\n' \
           'mod wsgi Test Page\n' \
           '</div>\n' \
           '</body>\n' \
           '</html>\n'
    response_header = [('Content-type','text/html')]
    start_response(status,response_header)
    return [html]
Error:
[wsgi:error] [pid 1062] [client 127.0.0.1:47306] TypeError: sequence of byte string values expected, value of type str found
I have tried various ways to convert the string but none are successful.

If I try b'mod wsgi Test Page\n' \ I get
Error:
html = '<html>\\n' \\ SyntaxError: cannot mix bytes and nonbytes literals
^
bytes('mod wsgi Test Page\n', encoding= 'utf-8')

I get:
Error:
[error]bytes('mod wsgi Test Page\\n', encoding= 'utf-8')
^
SyntaxError: invalid syntax[/error]

If I use:

def application(environ, start_response):
    status = '200 OK'
    output = b'This is my Website!'
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]
this works fine.