paulhammond / webkit2png

png screenshots of webpages

Home Page:http://www.paulhammond.org/webkit2png/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'ascii' codec can't encode character u'\u2019' in position 47: ordinal not in range(128)

dawnerd opened this issue · comments

WebKit discarded an uncaught exception in the webView:didFailLoadWithError:forFrame: delegate: <OC_PythonException> <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\u2019' in position 47: ordinal not in range(128)

Found this which might help: http://stackoverflow.com/questions/3224268/python-unicode-encode-error

Thanks for the bug report!

To help me reproduce this: do you have an example page that reliably this problem? And is your computer running in english or some other language?

My computer is in english. Did some reduction on the site I'm working on and anything under a certain screen size is redirected to mobile. I don't have the mobile code so it ends up 404ing, which in turn causes it to redirect again, and again.

I'd paste the html, but the project isn't public yet.

I've searched the code and that character just doesn't exist. There's only a couple pages, barely any text.

Some more info that may help: nodejs using jade to render the html, bootstrap, jquery and a google font called Oswald are loaded.

I could probably email you some of the code too.

Two things to check:

  1. Can you run python -c "import sys; print sys.stdout.encoding" and let me know what that says?
  2. Does running PYTHONIOENCODING=utf_8 webkit2png http://yoursite.com fix the problem?
  1. US-ASCII
  2. Gives me this:
troys-imac:~ troywhiteley$ PYTHONIOENCODING=utf_8 webkit2png http://localhost:3030/careers

Fetching http://localhost:3030/careers ...

 ... something went wrong: The operation couldn’t be completed. (NSURLErrorDomain error -999.)

That error has the ascii character it complains about.

There are actually two problems here:

  1. The page you're trying to screenshot causes an "NSURLErrorDomain -999 error", which is a harmless error that shouldn't cause the script to fail but does. About a month back I committed a fix to ignore this error (see discussion in #41); if you download the latest webkit2png development version it should be able to load your page.
  2. Your terminal is somehow set up to only handle ASCII characters, which is weird as the mac terminal has been able to handle unicode for a really long time. You might want to look at whether something is messing with your LANG environment variable (mine is LANG=en_US.UTF-8 if that helps). This problem isn't stopping the page from loading, but is stopping a more useful error message from being shown and might cause problems with other command line apps.

Weird thing is I have the latest version, that was actually the first thing I checked.

Thanks for looking into this!

Oh, weird. Try this test version and see if that works?

There's two error handlers, and only one of them ignores error -999. The version above ignores it in both places and might fix this problem.

Yep, that fixed the error.

Thanks again!

I just merged the fix - thanks for reporting the issue and helping debug it.

I have seen this error when passing an output directory path the character ~:

webkit2png -D "~/Desktop/" file:///Users/jorge/Sites/test/index.xhtml
webkit2png -D ~"/Desktop/" file:///Users/jorge/Sites/test/index.xhtml

whereas the following do work:

webkit2png -D ~/"Desktop/" file:///Users/jorge/Sites/test/index.xhtml
webkit2png -D "${HOME}/Desktop/" file:///Users/jorge/Sites/test/index.xhtml

Apparently happens whenever the output directory path contains non-ASCII characters.

Note that running python -c "import sys; print sys.stdout.encoding" gives me UTF-8.