Updated WOW posts. Separate "expected response" markup file

This commit is contained in:
Tom Keffer
2019-03-06 09:33:29 -08:00
parent fac4def22d
commit da5975efd6
4 changed files with 97 additions and 67 deletions

View File

@@ -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:
---
<html>
<head>
<title>PWS Weather Station Update</title>
</head>
<body>
Data Logged and posted in METAR mirror.
</body>
</html>
---
- If a bad station ID is given, it responds with a code of 200, and a response body with the following:
---
<html>
<head>
<title>PWS Weather Station Update</title>
</head>
<body>
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:
---
<html>
<head>
<title>PWS Weather Station Update</title>
</head>
<body>
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:
---
<html>
<head>
<title>PWS Weather Station Update</title>
</head>
<body>
dateutc parameter is not in proper format: YYYY-MM-DD HH:ii:ss<br>
Data parameters invalid, NOT logged.
</body>
</html>
---
"""
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:

View File

@@ -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:
```
<html>
<head>
<title>PWS Weather Station Update</title>
</head>
<body>
Data Logged and posted in METAR mirror.
</body>
</html>
```
* If a bad station ID is given, it responds with a code of 200, and a response body with the following:
```
<html>
<head>
<title>PWS Weather Station Update</title>
</head>
<body>
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:
```
<html>
<head>
<title>PWS Weather Station Update</title>
</head>
<body>
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:
```
<html>
<head>
<title>PWS Weather Station Update</title>
</head>
<body>
dateutc parameter is not in proper format: YYYY-MM-DD HH:ii:ss<br>
Data parameters invalid, NOT logged.
</body>
</html>
```
## 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.
```

View File

@@ -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

View File

@@ -1915,8 +1915,8 @@ longitude = -77.0366</pre>
<p class="config_important">password</p>
<p>Set to your WOW Authentication Key. Required. This is not the same as your WOW password but a 6 digit
numerical PIN.
<p>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.
</p>
<p class='config_option'>log_success</p>