UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position x188: ordinal not in

754 views
Skip to first unread message

laksh

unread,
Jul 24, 2017, 1:52:19 AM7/24/17
to OWASP ZAP User Group
Using Docker zap proxy (stable) with Python apis to automate the process. (Python 2.7). In this process, able to spider, scan and print alerts however when tried to generate report using zap.core.htmlreport() api facing bellow issue. Please guide.

Error details:
**************
Traceback (most recent call last):
  File "idenity_testing/script/identityWebSite_docker.py", line 109, in <module>
    html_file.write(html)
UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 180085: ordinal not in range(128)

Python script:
***************
html = zap.core.htmlreport()
html_file= open("/home/zap/wrk/ZAPalerts.html","w")
html_file.write(html)
html_file.close()


Note: Able to generate xml report, the problem with only html report. Please suggest.

Simon Bennetts

unread,
Jul 24, 2017, 6:04:15 AM7/24/17
to OWASP ZAP User Group
I think this is a problem with your code - you are trying to print unicode to an ascii file - you can search online for various options.
I found this, which might help: https://stackoverflow.com/questions/934160/write-to-utf-8-file-in-python

Cheers,

Simon

Grunny

unread,
Jul 24, 2017, 6:14:22 AM7/24/17
to zaprox...@googlegroups.com
Since it's Python 2.7, you should be able to fix this by simply opening the file with the "b" flag since your string is a byte string, i.e. the following should work fine:

html = zap.core.htmlreport()
with open("/home/zap/wrk/ZAPalerts.html", "wb") as html_file:
    html_file.write(html)

Hope that helps!

Cheers,
grunny


--
You received this message because you are subscribed to the Google Groups "OWASP ZAP User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zaproxy-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zaproxy-users/ca572e78-83dd-4f0d-bba0-6bb90fda6066%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

laksh

unread,
Jul 27, 2017, 12:39:43 PM7/27/17
to OWASP ZAP User Group
Thank you all for suggesting work arounds. Able to accomplish my task using/updating my python client api like below:
********************
import codecs

html = zap.core.htmlreport()
html_file = codecs.open("/zap/ZAPalerts.html", "w", "utf-8")
html_file.write(html)
html_file.close()

**********************
To unsubscribe from this group and stop receiving emails from it, send an email to zaproxy-user...@googlegroups.com.

kingthorin+owaspzap

unread,
Jul 27, 2017, 8:53:34 PM7/27/17
to OWASP ZAP User Group
Thanks for letting us know.
Reply all
Reply to author
Forward
0 new messages