Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locale.Error: unsupported locale setting in Python3.5.2 window7 #1

Closed
yifanshu02 opened this issue Dec 27, 2016 · 25 comments
Closed

locale.Error: unsupported locale setting in Python3.5.2 window7 #1

yifanshu02 opened this issue Dec 27, 2016 · 25 comments
Labels
help wanted can't get it up and running? just ask for help.

Comments

@yifanshu02
Copy link

hi @LoveBootCaptain ,
i saw your project by twitter, and at the same i see this project here.i'm a beginner in python,too. So i try to build this project. And i encounter an error:

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\WeatherPi_TFT-master\WeatherPi_TFT.py", line 16, in <module>
    locale.setlocale(locale.LC_ALL, locale.getdefaultlocale())
  File "D:\Python35\lib\locale.py", line 594, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

i dont know where is wrong.However,i annotate return _setlocale(category, locale) in "D:\Python35\lib\locale.py", line 594
and the error is gone
But there is a new error:

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\WeatherPi_TFT-master\WeatherPi_TFT.py", line 637, in <module>
    loop()
  File "C:\Users\Administrator\Desktop\WeatherPi_TFT-master\WeatherPi_TFT.py", line 602, in loop
    Update.run()
  File "C:\Users\Administrator\Desktop\WeatherPi_TFT-master\WeatherPi_TFT.py", line 410, in run
    Update.update_json()
  File "C:\Users\Administrator\Desktop\WeatherPi_TFT-master\WeatherPi_TFT.py", line 212, in update_json
    config = json.loads(config_data)
  File "D:\Python35\lib\json\__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "D:\Python35\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "D:\Python35\lib\json\decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 3 column 1 (char 59)

i have no idea about it...

PS: i can get defaultlocale by locale.getdefaultlocale():

>>> locale.getdefaultlocale()
('zh_CN', 'cp936')

Do you have a idea?

@LoveBootCaptain
Copy link
Owner

LoveBootCaptain commented Dec 27, 2016

hi there,

it seems there is an issue with your chinese locale settings. the script and the api require a UTF-8 compatible locale setting.

i guess you are trying it out on your local desktop computer with windows, right?

since i'm not a windows user since years i can`t give you a detailed instruction to set up a new locale in windows... perhaps you can add a new user that have a "en_US.UTF-8"-like locale?

by the way... the api request in the script is configured for a german respond... if you are a beginner, that seems some damn good quests to solve for you. ;) read the api documentation for any details how to configure the request and the respond. the request-url is constructed in the Update.update_json()-function

feel free to contact me, if you need more help.

@LoveBootCaptain LoveBootCaptain added the help wanted can't get it up and running? just ask for help. label Dec 27, 2016
@LoveBootCaptain
Copy link
Owner

Oh... and please rename your folder to "WeatherPi_TFT"... don't know when you cloned the repo... i made some fixes with "sys.path[0]" for Folder-PATH in the last commits to solve variable folder names for that application... or just update the project via git or download again ;)

@yifanshu02
Copy link
Author

@LoveBootCaptain ,thanks for your reply
Errors were excluded:

#locale.setlocale(locale.LC_ALL, locale.getdefaultlocale())
locale.setlocale(locale.LC_ALL, 'uk')

i find that the X in locale.setlocale(locale.LC_ALL, X) must be 2 byte. 'mai' and 'univ' do not work. i dont konw why

Then:
```
#config_data = open(PATH + 'config.json').read()

        #config = json.loads(config_data)

        #forecast_io_key = config['FORECAST_IO_KEY']

        forecast_io_key = 'f582cd3707f536dda08250505bfeea0c'
it is OK that i give key code to forecast_io_key,directly. it is not OK that give it though json.loads
i m confusing it.Maybe compatibility is poor?

@LoveBootCaptain
Copy link
Owner

LoveBootCaptain commented Dec 28, 2016

you can use setlocale to overwirte your default locale. but i think (at least in linux) you have to install this locale you want to use. that means when you want to use en_US and UTF-8 it has to be installed.

in locale.setlocale(locale.LC_ALL, locale.getdefaultlocale()) you have to pass in a tuple with language (e.g. en_US) and a encoding (e.g. UTF-8) for locale.getdefaultlocale()

e.g.: locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8'))

i don't know what happen, if you uncomment this completely... i needed to use it to solve problems with strange characters like german umlauts (ä, ö, ü, ß), which come from the API (like in forecast-summary strings).

long story short: be shure you set the API request to use english as language AND your os should be set up to en_US and UTF-8 too and it should work.

here is an API request you can use (weather is from New York):
https://api.forecast.io/forecast/YOUR_API_KEY/40.7058253,-74.1180847?lang=en&units=si&exclude=flags

you don't have to use API key from the json file. just overwrite the hole request_url-variable with the url above and insert your API key.

please do not share your secret keys ;) you can reset it in the account settings of https://darksky.net/dev/account
thats the reason i used a json file for configuration... my config.json is excluded in my project so i do not commit my secret key here on github by accident ;) and i thought it is a good idea if i want to add more configuartion without changing the script... (like display brightness or intervals for the API-updates).

your first json error looks like you probably missed the double quotes for the key or the value. just replace the xxxx with your API-key but not the " " ;) . it has to look this (no comma at the end -> i have to change that in the example):

{
    "FORECAST_IO_KEY": "xxxxxxxxxxxxxxxxxxxxxxxxx"
}

hope this helps ;) just tried it on a fresh and new installed jessie-raspbian... it runs out of the box on a raspberry pi with latest raspbian image with english locale.

@yifanshu02
Copy link
Author

Thanks for your suggestion!

About json error ,i have found the key.Yesterday my json is:

{
    "FORECAST_IO_KEY": "xxxxxxxxxxxxxxxxxxxxxxxxx",
}

now i remove the last ',' .and the code is working......
what a boring ','!
AND i suggest the geographic coordinate values, lang,units,exclude should be added to config.json

@LoveBootCaptain
Copy link
Owner

LoveBootCaptain commented Dec 28, 2016 via email

@yifanshu02
Copy link
Author

About the setlocale .in the locale.py there is
'uk': 'uk_UA.KOI8-U',

In the project,the code 'locale.setlocale(locale.LC_ALL, 'uk_UA.KOI8-U')' is not working
However, the code 'locale.setlocale(locale.LC_ALL, 'uk')' is working
:(

@LoveBootCaptain
Copy link
Owner

LoveBootCaptain commented Dec 28, 2016

ah great.

it has to be a tuple in XX locale.setlocale(locale.LC_ALL, XX). means it has to be locale.setlocale(locale.LC_ALL, ('uk_UA', 'KOI8-U')) in your case.

'uk' is returning this correctly. that's why it works ;)

@yifanshu02
Copy link
Author

In addition,when i use locale.setlocale(locale.LC_ALL, '') or locale.setlocale(locale.LC_ALL, 'zh')
the UI do not show some character at the position of "week" and "month"

@LoveBootCaptain
Copy link
Owner

this could be cause the font don't has that special character... feel free to change the font to one which has that. it has to be in .ttf-format. there are some other fonts in the folder which might work. you can also use one of your system fonts. see http://www.pygame.org/docs/ref/font.html for more details or just copy/paste a .ttf file to the /font folder

(i know this problems cause of the german umlauts (ä, ö, ü) too... hate those crazy umlauts like those commas i missed to remove in examples 😂 )

@yifanshu02
Copy link
Author

I use the locale.setlocale(locale.LC_ALL, 'uk').everything is OK.
I think when i use locale.setlocale(locale.LC_ALL, 'zh'),the UI should show Chinese.but the .ttf in /font have not Chinese
And locale.setlocale(locale.LC_ALL, ('uk_UA', 'KOI8-U')) do not work.......:(

@LoveBootCaptain
Copy link
Owner

LoveBootCaptain commented Dec 28, 2016

if you find a font which looks good on the device or a Roboto-Chinese-Font feel free to add it via pull request. the equivalent of Roboto-Font in android and chrome is Noto-Font (https://material.io/guidelines/style/typography.html#typography-typeface), here is a link to google fonts: https://fonts.google.com/specimen/Noto+Sans?selection.family=Noto+Sans.

perhaps the locale issue is related to os? who knows... in mac os and linux it works... on windows not... locale.setlocale(locale.LC_ALL, 'de') is not working on my raspberry 😂 i need the long form for my system-locale

@yifanshu02
Copy link
Author

All right,I will try it .
locale.setlocale(locale.LC_ALL, 'de') is working on window7.I will try it on my RPI2 and 2.2'TFT
Now i think accuracy of weather forecast of your code is higher than squix78's code
and accuracy of your code about moon change seem not higher than squix78's code
img_5517

@LoveBootCaptain
Copy link
Owner

LoveBootCaptain commented Dec 28, 2016

about the moon issue:

the moon-phase is provided via API (and the Temp-Data too) which might be the difference. squix78 is using another API (wonderground). i use darksky (forecast.io). darksky is providing moonphase in a value which is percentage.
today there is 0.97 provided via darksky for Berlin, Germany. Which means 1% of the moon should be visible. here is a link to a moonphase calender: http://www.kalender-365.eu/mond/aktueller-mondstand.html which tells is 1% is visible too...

my icons are 28 for 31 possible moonphases. i do a little math in moon_icon = int((float(moon_icon) * 100 / 3.57) + 0.25) to map the percentage to 28 icons.

i guess for 1% visible moon it is ok... for squix78 and my code 😂 1% is nearly unvisible.
i can make some more small icons to make it more detailed... but the icons from the source are only 28 😈

@yifanshu02
Copy link
Author

AHAHAHAH,
1%MOON...............................
YOU WIN

@LoveBootCaptain
Copy link
Owner

Please share a picture with chinese font if you get it working.
feel free to contact me again if you have any further issues or contribute your improvements.
kind regards from Berlin (without snow, too)

@LoveBootCaptain
Copy link
Owner

LoveBootCaptain commented Dec 28, 2016

let it snow let it snow let it snow

p.s.: you should change the hardcoded "Schnee" for "snow" with a language that fits you.
its PRECIPTYPE in Update.get_precip_type()
Same for some other hardcoded german stuff 🇩🇪

@yifanshu02
Copy link
Author

AHAHAH,global warming in 10+ years made the weather abnormal,In winter some parts of China are suffering form haze:(

@LoveBootCaptain
Copy link
Owner

just pushed the updated config.json with more options...
next push will include a linux service for buttons to restart weather app or reboot raspberry pi.
regards

@yifanshu02
Copy link
Author

i have see the new config.json~
Chinese weatherPI_TFT:

font_small = pygame.font.SysFont('SimHei', 14)
font_big = pygame.font.SysFont('SimHei', 36)

font_small_bold = pygame.font.SysFont('SimHei', 14)
font_big_bold = pygame.font.SysFont('SimHei', 36)

default

and :

font_small = pygame.font.Font(FONT_PATH + 'msyh.ttf', 14)
font_big = pygame.font.Font(FONT_PATH + 'msyh.ttf', 30)

font_small_bold = pygame.font.Font(FONT_PATH + 'msyh.ttf', 14)
font_big_bold = pygame.font.Font(FONT_PATH + 'msyh.ttf', 30)

yh

Sure that modify the API lang to zh:options = '?lang=zh&units=si&exclude=flags'
and locale.setlocale(locale.LC_ALL, 'zh')

@LoveBootCaptain
Copy link
Owner

looks crazy in chinese 🤣 great work
font looks awesome too

a good translation of "Niederschlag" would be "rainfall" or "precipitation"
http://en.bab.la/dictionary/english-chinese/rainfall

please don't modify your last post... i will use it as a link for troubleshooting

@Mutley247365
Copy link

HI Guys,
I have been trying to ge this running on a pi4 and a HDMI 4" TFT, but being so new to Pi I cant seam to get this running on boot up.

@rb69git
Copy link

rb69git commented Jan 26, 2024

HI Guys, I have been trying to ge this running on a pi4 and a HDMI 4" TFT, but being so new to Pi I cant seam to get this running on boot up.

It just works as is! I assume you got API from https://www.weatherbit.io/. rest commands as straight forward. I am running on Pi 3 4 5 and both HDMI, DSI and hyperpixel LCDs.

By the way are you able to boot up to PI desktop?

@rb69git
Copy link

rb69git commented Jan 26, 2024

Question to author / all

the precipitation pulled and displayed is for DAILY - issue is if morning there is some% rain evening as well it shows DAILY PRECEPTATION % and ICON. Better I change it to CURRENT. Not able to do so. Let me know which line of code needs to be changed.

@Outlaws2000
Copy link

HI Guys, I have been trying to ge this running on a pi4 and a HDMI 4" TFT, but being so new to Pi I cant seam to get this running on boot up.

It just works as is! I assume you got API from https://www.weatherbit.io/. rest commands as straight forward. I am running on Pi 3 4 5 and both HDMI, DSI and hyperpixel LCDs.

By the way are you able to boot up to PI desktop?

Hi I'm trying for 4 days now to get it work. i've follw the steps for installation. got myself a api.key. and able te see the desktop.
no errors while booting up. still no weather scree on display. it stays on desktop. did i forgot something to edit or add? please help, i'm new at raspberry (zero). how to display the weather screen? many thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted can't get it up and running? just ask for help.
Projects
None yet
Development

No branches or pull requests

5 participants