[Openstack-operators] python and nice utf ö ü :)

Matt Jarvis matt.jarvis at datacentred.co.uk
Wed Aug 31 13:25:04 UTC 2016


I'm no python guru, but if you're getting unicode output from the python
openstack tools then don't you want to prepend your strings with u in the
print statements ?

On 31 August 2016 at 14:03, Saverio Proto <zioproto at gmail.com> wrote:

> Oh,
> to stick with the subject of the email you can also call the instance
> for example
>
> füöô
>
> and this will trigger the bug anyway :)
>
> Saverio
>
>
>
>
> 2016-08-31 14:54 GMT+02:00 Saverio Proto <zioproto at gmail.com>:
> > Hello Matt,
> >
> > I am sorry, I realize now I sent a very dumb email :) I will try to
> > explain my self better.
> >
> > The script fails to print some resources. To reproduce the bug do the
> following,
> >
> > Create a instance and name it:
> >
> > آشپزی ایتالیایی
> >
> > then just call
> >
> > python user-info.py <username>
> >
> > (of course the username is the one that created the instance)
> >
> > this will print all the instances, including the one with the
> > problematic name. Of course you will get an Error. It will raise an
> > exception and will fail.
> >
> > the patch I proposed shows how to get a traceback that makes sense,
> > you will get something like:
> >
> > UnicodeEncodeError: 'ascii' codec can't encode characters in position
> > 0-3: ordinal not in range(128)
> >
> >
> > Adding this two lines:
> > reload(sys)
> > sys.setdefaultencoding("utf-8")
> >
> > fixes the problem, I dont have anymore the exception
> > UnicodeEncodeError and I see printed:
> >
> > Server: نواع-پاستاها-و-طرز-ط [3f26242c-440b-4a2e-b3ca-cb6c6c7ee8b2] -
> ACTIVE
> >
> > But on stackoverflow people say that these two lines I added are bad,
> > so what should I do ? :)
> >
> > thank you !
> >
> > Saverio
> >
> >
> >
> > 2016-08-31 14:13 GMT+02:00 Matt Jarvis <matt.jarvis at datacentred.co.uk>:
> >> What was your problem to start with ?
> >>
> >> On 31 August 2016 at 12:56, Saverio Proto <zioproto at gmail.com> wrote:
> >>>
> >>> Hello ops,
> >>>
> >>> this patch fixed my problem:
> >>>
> >>> https://review.openstack.org/#/c/361308/
> >>>
> >>> but it is an ugly hack according to:
> >>>
> >>>
> >>> http://stackoverflow.com/questions/3828723/why-should-we-not-use-sys-
> setdefaultencodingutf-8-in-a-py-script
> >>>
> >>> anyone knows how to make it better ?
> >>>
> >>> Saverio
> >>>
> >>> _______________________________________________
> >>> OpenStack-operators mailing list
> >>> OpenStack-operators at lists.openstack.org
> >>> http://lists.openstack.org/cgi-bin/mailman/listinfo/
> openstack-operators
> >>
> >>
> >>
> >> DataCentred Limited registered in England and Wales no. 05611763
>

-- 
DataCentred Limited registered in England and Wales no. 05611763
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-operators/attachments/20160831/c4413396/attachment.html>


More information about the OpenStack-operators mailing list