From da5975efd608edcfd7f02bc64e7e0ed525b345bf Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Wed, 6 Mar 2019 09:33:29 -0800 Subject: [PATCH] Updated WOW posts. Separate "expected response" markup file --- bin/weewx/restx.py | 72 ++++----------------------------- bin/weewx/tests/restful.md | 83 ++++++++++++++++++++++++++++++++++++++ docs/changes.txt | 5 ++- docs/usersguide.htm | 4 +- 4 files changed, 97 insertions(+), 67 deletions(-) create mode 100644 bin/weewx/tests/restful.md diff --git a/bin/weewx/restx.py b/bin/weewx/restx.py index 0e64c3b9..87a3cd59 100644 --- a/bin/weewx/restx.py +++ b/bin/weewx/restx.py @@ -66,66 +66,9 @@ In unusual cases, you might also have to implement the following: See the CWOP version, CWOPThread.process_record(), for an example that uses sockets. -=================== Known behavior of various RESTful services: =================== +See the file restful.md in the "tests" subdirectory for known behaviors +of various RESTful services. -==== Wunderground (checked 5-Mar-2019) - If all is OK, it responds with a code of 200, and a response body of 'success'. - - If either the station ID, or the password is bad, it responds with a code of 401, - and a response body of 'unauthorized'. - - If the GET statement is malformed (for example, the date is garbled), it responds - with a code of 400, and a response body of 'bad request'. - -==== PWS (checked 6-Mar-2019) - - If all is OK, it responds with a code of 200 and a response body with the following: - ---- - - - PWS Weather Station Update - - -Data Logged and posted in METAR mirror. - - - ---- - - - If a bad station ID is given, it responds with a code of 200, and a response body with the following: ---- - - - PWS Weather Station Update - - -ERROR: Not a vailid Station ID ---- - - - If a valid station ID is given, but a bad password, it responds with a code of 200, and a - response body with the following: ---- - - - PWS Weather Station Update - - -ERROR: Not a vailid Station ID/Password ---- - - - If the date is garbled, it responds with a code of 200, and a response body with the following: ---- - - - PWS Weather Station Update - - -dateutc parameter is not in proper format: YYYY-MM-DD HH:ii:ss
-Data parameters invalid, NOT logged. - - - ---- """ from __future__ import absolute_import @@ -155,7 +98,7 @@ from weeutil.weeutil import to_int, to_float, to_bool, timestamp_to_string, sear from weeutil.log import logdbg, logerr, loginf, logcrt, logalt class FailedPost(IOError): - """Raised when a post fails after trying the max number of allowed times""" + """Raised when a post does not succeed.""" class AbortedPost(Exception): @@ -792,7 +735,6 @@ class StdWOW(StdRESTful): config_dict, 'wx_binding') _ambient_dict.setdefault('server_url', StdWOW.archive_url) - _ambient_dict.setdefault('post_interval', 900) self.archive_queue = queue.Queue() self.archive_thread = WOWThread(self.archive_queue, _manager_dict, protocol_name="WOW", @@ -935,7 +877,7 @@ class AmbientThread(RESTThread): # Bad login. No reason to retry. Raise an exception. raise BadLogin(line) # PWS signals something garbled with a line that includes 'invalid'. - elif line.find(b'invalid'): + elif line.find(b'invalid') != -1: # Again, no reason to retry. Raise an exception. raise FailedPost(line) @@ -1046,9 +988,11 @@ class WOWThread(AmbientThread): try: _response = urllib.request.urlopen(request, timeout=self.timeout) except urllib.error.HTTPError as e: - # WOW signals a bad login with a HTML Error 400 or 403 code: - if e.code == 400 or e.code == 403: + # WOW signals a bad login with a HTML Error 403 code: + if e.code == 403: raise BadLogin(e) + elif e.code == 429: + raise FailedPost("Too many requests; data already seen; or too out of date.") else: raise else: diff --git a/bin/weewx/tests/restful.md b/bin/weewx/tests/restful.md new file mode 100644 index 00000000..dccff96a --- /dev/null +++ b/bin/weewx/tests/restful.md @@ -0,0 +1,83 @@ +# Known behavior of various RESTful services + +## Wunderground (checked 5-Mar-2019) +* If all is OK, it responds with a code of 200, and a response body of `success`. + +* If either the station ID, or the password is bad, it responds with a code of 401, and a response body of `unauthorized`. + +* If the GET statement is malformed (for example, the date is garbled), it responds +with a code of 400, and a response body of `bad request`. + +## PWS (checked 6-Mar-2019) +* If all is OK, it responds with a code of 200 and a response body with the following: + + ``` + + + PWS Weather Station Update + + + Data Logged and posted in METAR mirror. + + + + ``` + +* If a bad station ID is given, it responds with a code of 200, and a response body with the following: + ``` + + + PWS Weather Station Update + + + ERROR: Not a vailid Station ID + ``` + +* If a valid station ID is given, but a bad password, it responds with a code of 200, and a +response body with the following: + ``` + + + PWS Weather Station Update + + + ERROR: Not a vailid Station ID/Password + ``` + +* If the date is garbled, it responds with a code of 200, and a response body with the following: + ``` + + + PWS Weather Station Update + + + dateutc parameter is not in proper format: YYYY-MM-DD HH:ii:ss
+ Data parameters invalid, NOT logged. + + + + ``` + +## WOW (checked 6-Mar-2019) +* If all is OK, it responds with a code of 200, and an empty JSON response body: + ``` + {} + ``` + +* If a valid station ID is given, but a bad password, it responds with a code of 403, and a +response body with the following: + ``` + You do not have permission to view this directory or page. + ``` + +* If the GET is garbled (e.g., a bad date), it responds with code 400, and response body +with the following: + ``` + Bad Request + ``` + +* If a post is done too soon (or, has already been seen, or is out of date --- not sure), it responds with code 429 ("Too many requests"), and a response body with the +following + ``` + The custom error module does not recognize this error. + ``` \ No newline at end of file diff --git a/docs/changes.txt b/docs/changes.txt index 3ba367b4..a05ac2ec 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -10,7 +10,10 @@ The package MySQL-python, which we used previously, is not available for Python 3. Ported the MySQL code to use the package mysqlclient as an alternative. -Introduce a uniform logging shim. Fixes issue #353, +Introduce a uniform logging shim. Fixes issue #353. + +The default for WOW no longer throttles posting frequency (the default +used to be no more than once every 15 minutes). 3.10.0 MM/DD/YYYY diff --git a/docs/usersguide.htm b/docs/usersguide.htm index f7e6e226..c7a753a6 100644 --- a/docs/usersguide.htm +++ b/docs/usersguide.htm @@ -1915,8 +1915,8 @@ longitude = -77.0366

password

-

Set to your WOW Authentication Key. Required. This is not the same as your WOW password but a 6 digit - numerical PIN. +

Set to your WOW Authentication Key. Required. This is not the same as your WOW user password. It is + a 6 digit numerical PIN, unique for your station.

log_success