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

Cannot Get Weather, latitude #108

Open
elijamesn01 opened this issue Jul 18, 2018 · 10 comments
Open

Cannot Get Weather, latitude #108

elijamesn01 opened this issue Jul 18, 2018 · 10 comments

Comments

@elijamesn01
Copy link

Upon startup of the program, I receive this error message and the weather does not appear on the monitory.

Traceback (most recent call last) :
File "smartmirror.py", line 145, in get_weather
lat = location_obj[ 'latitude' ]
KeyError: 'latitude'
Error: 'latitude'. Cannot get weather.

After tinkering with the code for several hours I am at a loss.
Any help is appreciated!

@sajuran123
Copy link

Hey

Try to use this link to find your latitude and longtitude: http://www.mapcoordinates.net/en
Type the numbers in and you will recieve the right weather data.

Best regards

Sajuran

@elijamesn01
Copy link
Author

Withing the program it says I must enter the coordinates in as a string. I am very very new to programming and do not know how to do that

@toottRenat
Copy link

Current version of weather API is depricated, so SmartMirror needs to be updated.
Here is message that you get as dictionary location_obj:

0 #################################################################################################################################
1 #                                                                                                                               #
2 # IMPORTANT - PLEASE UPDATE YOUR API ENDPOINT                                                                                   #
3 #                                                                                                                               #
4 # This API endpoint is deprecated and has now been shut down. To keep using the freegeoip API, please update your integration   #
5 # to use the new ipstack API endpoint, designed as a simple drop-in replacement.                                                #
6 # You will be required to create an account at https://ipstack.com and obtain an API access key.                                #
7 #                                                                                                                               #
8 # For more information on how to upgrade please visit our Github Tutorial at: https://github.com/apilayer/freegeoip#readme      #
9 #                                                                                                                               #
a #################################################################################################################################

There 0-a are keys and text after them represents values. To get this message add following code before error line:

for k, v in location_obj.items():
    print(k, v)

@PySecNinja
Copy link

After typing in your new code I am getting the error message

Traceback (most recent call last) :
File "smartmirror.py", line 146, in get_weather
lat = location_obj[ 'latitude' ]
KeyError: 'latitude'
Error: 'latitude'. Cannot get weather.

@keroe
Copy link

keroe commented Oct 2, 2018

Hi
In line 26&27 you will find the parameters latitude & longitude.
It looks like this:
latitude = None
longitude = None
You need to change those parameters to your location. You can use the link sajuran provided above.
For example for New York it should look like this:
latitude = '40'
longitude = '-73'

@PySecNinja
Copy link

@keroe @sajuran123 @elijamesn01 @toottRenat
Even changing the lat and long in line 26 and 27 I am now getting this error
Tried researching everything please help Thanks!

pi@pi:~/Smart-Mirror $ python smartmirror.py
Traceback (most recent call last):
File "smartmirror.py", line 159, in get_weather
weather_obj = json.loads(r.text)
File "/usr/lib/python2.7/json/init.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Error: No JSON object could be decoded. Cannot get weather.

@toottRenat
Copy link

@Ahendrix9624
Try using code from my pull request (it uses new API for getting weather), as least it works fine for me.
Or supply some more information with different prints like

for k, v in location_obj.items():
    print(k, v)

or maybe printing r.text.

@PySecNinja
Copy link

@toottRenat I think my string format is wrong for the location_req_url
I typed it just like your pull request and used my own api link this type

Traceback (most recent call last):
File "smartmirror.py", line 141, in get_weather
location_req_url = 'http://api.ipstack.com/104.137.46.10?access_key=b8c717cddda21de63b6a47735aaadcda' % (self.get_ip(),ip_stack_key)
TypeError: not all arguments converted during string formatting
Error: not all arguments converted during string formatting. Cannot get weather.

@toottRenat
Copy link

Yes, your string format is wrong. In your string you should replace ip and key by "%s", or completely remove string format (% and everything after it).

@MitchNetz
Copy link

        @toottRenat's fix works great for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants