Rich-text Reply

UnicodeDecodError in Django when pointing optimizely to localhost

jkhulme 02-27-15

UnicodeDecodError in Django when pointing optimizely to localhost

Hi,

 

I'm trying to test my experiments locally before pushing to the live version of the site, so my experiment is targeted to:

    • localhost:8000/ (simple match)

The experiment preview however doesn't load.  If I point to the live version of the site it works fine.  

 

Its a django app, viewing the source when I go localhost:8000 in the browser I can see that the optimizely snippet is present.

 

This is my stacktrace from django

self.finish_request(request, client_address)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Users/james/pubfront/riidr_venv/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 126, in __init__
Exception happened during processing of request from ('127.0.0.1', 59660)
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 655, in __init__
self.handle()
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 599, in process_request_thread
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/simple_server.py", line 124, in handle
self.finish_request(request, client_address)
if not self.parse_request(): # An error code has been sent, just exit
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 286, in parse_request
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 334, in finish_request
self.send_error(400, "Bad request syntax (%r)" % requestline)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 368, in send_error
self.RequestHandlerClass(request, client_address, self)
File "/Users/james/pubfront/riidr_venv/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 126, in __init__
self.send_response(code, message)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 385, in send_response
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
self.log_request(code)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 655, in __init__
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 422, in log_request
self.handle()
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/simple_server.py", line 124, in handle
self.requestline, str(code), str(size))
File "/Users/james/pubfront/riidr_venv/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 138, in log_message
msg = "[%s] %s\n" % (self.log_date_time_string(), format % args)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 5: ordinal not in range(128)

 

 

I doubt its a problem with the code as it works fine with the live version, I think I must be missing something to do with pointing optimizely at localhost.

 

Any suggestions will be much appreciated

 

Level 1

Joel_Balmer 03-02-15
 

Re: UnicodeDecodError in Django when pointing optimizely to localhost

Hi there!

 

The preview function works by navigating to the URL in the editor settings, and appending the URL with Optimizely query parameters in order display this content. If the snippet can't be found, we use a proxied snippet and host the page ourselves. This fall-back version of previewing an experiment can lead to incorrect displaying of content some resources missing, etc.

 

Can I ask what you mean by failing to load - where URL the preview mode takes you to, and whether the URL returns an error or the page never finishes loading, etc.? And also, could you let us know if you receive any errors printed to the browser javascript console?

 

It is also possible to use the 'force variation parameter' to test on your live site using this method - simply point your URL targeting to the live site, and rather than run the experiment you can follow this guide, here.

 

If your setup looks something similar to this:

 

Localhost.jpg

 

Then you should be able to re-point your URL targeting to your live site and test using the force variation parameter, as above.

 

I hope that helps!