[RELEASE] OzWeather - Australian Weather Addon using BOM data

  Thread Rating:
  • 4 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
[email protected] Offline
Junior Member
Posts: 13
Joined: Jul 2016
Reputation: 0
Post: #706
I think I have pretty much worked out where things are happening.

In default.py at lines 491-526 this happens:
491 log("Download the radar loop")
492 image = urllib.URLopener()
493 files = []
494
495 log("Log in to BOM FTP")
496 ftp = ftplib.FTP("ftp.bom.gov.au")
497 http://ftp.login("anonymous", "[email protected]")
498 http://ftp.cwd("/anon/gen/radar/")
499
500 log("Get files list")
501 #connected, so let's get the list
502 try:
503 files = http://ftp.nlst()
504 except ftplib.error_perm, resp:
505 if str(resp) == "550 No files found":
506 log("No files in BOM ftp directory!")
507 else:
508 log("Something wrong in the ftp bit of radar images")
509
510 log("Download the files...")
511 #ok now we need just the matching radar files...
512 loopPicNames = []
513 for f in files:
514 if radarCode in f:
515 loopPicNames.append(f)
516
517 #download the actual images, might as well get the longest loop they have
518 for f in loopPicNames:
519 #ignore the composite gif...
520 if f[-3:] == "png":
521 imageToRetrieve = "ftp://anonymous:[email protected]//anon/gen/radar/" + f
522 log("Retrieving radar image: " + imageToRetrieve)
523 try:
524 image.retrieve(imageToRetrieve, LOOP_IMAGES_PATH + "/" + f )
525 except Exception as inst:
526 log("Failed to retrieve radar image: " + imageToRetrieve + ", oh well never mind!", inst )

except that it looks as if the loop 518-526 is only happening once because only one file (the oldest) is retrieved.
I've tried a wget to simulate 500-508 and I get a full list of files, and there are 11 that are relevant to my particular radar

OK, progress.
I turned on logging and lo behold:

22:05:30 T:140010405742336 DEBUG: ### Oz Weather - 0.8.1 ### Download the files...
22:05:30 T:140010405742336 DEBUG: ### Oz Weather - 0.8.1 ### Retrieving radar image: http://ftp.anonymous:someone%40somewhere...au//anon/g
en/radar/IDR492.T.201607251000.png
22:05:30 T:140010405742336 DEBUG: ### Oz Weather - 0.8.1 ### Retrieving radar image: http://ftp.anonymous:someone%40somewhere...au//anon/g
en/radar/IDR492.T.201607251010.png
22:05:30 T:140010405742336 DEBUG: ### Oz Weather - 0.8.1 ### Failed to retrieve radar image: http://ftp.anonymous:someone%40somewhere...bom.gov.au
//anon/gen/radar/IDR492.T.201607251010.png, oh well never mind!
22:05:30 T:140010405742336 DEBUG: ### Oz Weather-0.8.1 ### Exception:Traceback (most recent call last):
File "/home/howard/.kodi/addons/weather.ozweather/default.py", line 524, in buildImages
image.retrieve(imageToRetrieve, LOOP_IMAGES_PATH + "/" + f )
File "/usr/lib/python2.7/urllib.py", line 245, in retrieve
fp = self.open(url, data)
File "/usr/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 558, in open_ftp
(fp, retrlen) = self.ftpcache[key].retrfile(file, type)
File "/usr/lib/python2.7/urllib.py", line 906, in retrfile
conn, retrlen = self.ftp.ntransfercmd(cmd)
File "/usr/lib/python2.7/ftplib.py", line 334, in ntransfercmd
host, port = self.makepasv()
File "/usr/lib/python2.7/ftplib.py", line 312, in makepasv
host, port = parse227(self.sendcmd('PASV'))
File "/usr/lib/python2.7/ftplib.py", line 830, in parse227
raise error_reply, resp
IOError: [Errno ftp error] 200 Switching to Binary mode.
22:05:30 T:140010405742336 DEBUG: ### Oz Weather - 0.8.1 ### Retrieving radar image: http://ftp.anonymous:someone%40somewhere...au//anon/g
en/radar/IDR492.T.201607251020.png
22:05:31 T:140010405742336 DEBUG: ### Oz Weather - 0.8.1 ### Failed to retrieve radar image: http://ftp.anonymous:someone%40somewhere...bom.gov.au
//anon/gen/radar/IDR492.T.201607251020.png, oh well never mind!


It's getting the first image and then barfing on the subsequent images.

I'll keep digging unless others can provide pointers Smile

TIA
find quote
[email protected] Offline
Junior Member
Posts: 13
Joined: Jul 2016
Reputation: 0
Post: #707
I think I have to give up at this point.

File "/usr/lib/python2.7/ftplib.py", line 830, in parse227
raise error_reply, resp

Looking at the code it appears that python is expecting an error code 227 back from the ftp and isn't getting it. This only appears to happen on the second and subsequent calls to the server.

I think I have met the proverbial brick wall Sad
find quote
[email protected] Offline
Junior Member
Posts: 13
Joined: Jul 2016
Reputation: 0
Post: #708
Back looking at this in daylight, I installed OSMC on a spare Raspberyy Pi B+, and - everything works fine. Admittedly Live TV is very jerky so it might be the motivation I need to buy a Raspberry Pi 3. I would still like to know why I have problems on a mid range Asus laptop. Hey Ho, c'est la vie.
find quote
[email protected] Offline
Junior Member
Posts: 13
Joined: Jul 2016
Reputation: 0
Post: #709
I have noticed some differences between the ftplib.py files on the two machines that I have Kodi running on, but not in the parse227 function which is where the error is being thrown.

What I have notice is that the library file that is failing has this line:
ssl_version = ssl.PROTOCOL_SSLv23
and the one that works has this line:
ssl_version = ssl.PROTOCOL_TLSv1

I'm not sure if there is any significance in this difference, maybe I should suck it and see.
find quote
[email protected] Offline
Junior Member
Posts: 13
Joined: Jul 2016
Reputation: 0
Post: #710
I thought I had something to go with when I came across this:
https://bugs.python.org/issue1067702
which presents the problem when using python 2.7

I discovered that /usr/bin/python is symlinked to /usr/bin/python2.7 so I changed the symlink to point to /usr/bin/python3.5 and rebooted (to be safe), but when i run Kodi the log still refers to python2.7

Baffled does not describe it.
find quote
Gigantur Offline
Senior Member
Posts: 185
Joined: Dec 2012
Reputation: 1
Location: Melbourne, Australia
Post: #711
Not sure if relevant .

On Mac, kodi comes with its own Python which has a known ssl/cert issue with a fix in progress - not sure if Linux is the same ..

If in Linux you find kodi uses local Python you may need to easy install OpenSSL ..
find quote
[email protected] Offline
Junior Member
Posts: 13
Joined: Jul 2016
Reputation: 0
Post: #712
Im inclined to think it's an issue with Ubuntu 16.04 and their version of python 2.7

I don't have the problem on Ubuntu 14.04 nor on Raspian

I might have to find another box to do another 16.04 install on to test it. At this stage I'm disinclined to update those boxes that are working.
find quote
[email protected] Offline
Junior Member
Posts: 13
Joined: Jul 2016
Reputation: 0
Post: #713
On a quite different tack; is there any way to alter the BoM weather map refresh rate automatically.
The images are available every 10 minutes but the refresh appears to be about every 30 minutes.
I am aware that it can be refreshed manually, but this is not what I want.
find quote
bossanova808 Offline
Donor
Posts: 2,746
Joined: Sep 2009
Reputation: 52
Location: Melbourne, Australia
Post: #714
No, the update frequency is determined by Kodi itself.

I didn't see all these replies - sorry. If you can make it work in 16.04 I'm happy to add whatever fix, but I don't have any 16.04 setups myself

Sorry, no help w/out a *full debug log*
find quote
dbiczo Offline
Junior Member
Posts: 2
Joined: Aug 2016
Reputation: 0
Post: #715
Changing from urllib to urlib2 seems to fix the static radar image download problem on Ubuntu 16.04.

Here is a snippet of my modified code from default.py:

517 #download the actual images, might as well get the longest loop they have
518 for f in loopPicNames:
519 #ignore the composite gif...
520 if f[-3:] == "png":
521 imageToRetrieve = "ftp://anonymous:[email protected]//anon/gen/radar/" + f
522 log("Retrieving radar image: " + imageToRetrieve)
523 try:
524 # image.retrieve(imageToRetrieve, LOOP_IMAGES_PATH + "/" + f )
000 radarImage = urllib2.urlopen(imageToRetrieve)
000 fh = open( LOOP_IMAGES_PATH + "/" + f , "wb")
000 fh.write(radarImage.read())
000 fh.close()

525 except Exception as inst:
526 log("Failed to retrieve radar image: " + imageToRetrieve + ", oh well never mind!", inst )
find quote
bossanova808 Offline
Donor
Posts: 2,746
Joined: Sep 2009
Reputation: 52
Location: Melbourne, Australia
Post: #716
Have you tested in 14.04 as well?

@dbiczo

Ideally, can you do a pull request:

https://github.com/bossanova808/weather.ozweather

Sorry, no help w/out a *full debug log*
(This post was last modified: 2016-08-11 08:35 by bossanova808.)
find quote
dbiczo Offline
Junior Member
Posts: 2
Joined: Aug 2016
Reputation: 0
Post: #717
Have tested in Ubuntu 14.04 & 16.04, Raspberry Pi OSMC & Fedora 24.
Have also created a pull request. My first time creating a pull request hopefully it is OK.Confused
find quote
bossanova808 Offline
Donor
Posts: 2,746
Joined: Sep 2009
Reputation: 52
Location: Melbourne, Australia
Post: #718
Seems spot on to me, and thanks! I'll get u proper update happening soon.

Sorry, no help w/out a *full debug log*
find quote
[email protected] Offline
Junior Member
Posts: 13
Joined: Jul 2016
Reputation: 0
Post: #719
(2016-08-02 03:25)bossanova808 Wrote:  No, the update frequency is determined by Kodi itself.

I didn't see all these replies - sorry. If you can make it work in 16.04 I'm happy to add whatever fix, but I don't have any 16.04 setups myself

I thought that might be the case, but do you have any idea where it happens in Kodi? I've pulled the source off Github and am grepping through it and /usr/share/kodi looking for likely places where the frequency is set.

BTW, when downloading the BoM backgrounds I would suggest that you replace the 'catchments' background with the 'waterways' background - it's more relevant as a map component.
find quote
bossanova808 Offline
Donor
Posts: 2,746
Joined: Sep 2009
Reputation: 52
Location: Melbourne, Australia
Post: #720
I'll test the above changes and try the waterways bg thing - although ancient memory tells me there was a reason I didn't choose that, I can't recall it right now...and things may have changed anyway since I wrote it way back in 2011 (!)

Sorry, no help w/out a *full debug log*
(This post was last modified: 2016-08-13 07:25 by bossanova808.)
find quote
Post Reply