I was in the process of updating restx.py to log the returned error 
message. If you want the stations api to return a 400, you could do 
something like this. 

def test_post():
    url = 'http://localhost:5000/api/v2/stations/'

    body = {
        'station_url': 'example.com',
        }
    json_body = json.dumps(body)

    request = urllib.request.Request(url)
    request.add_header('Content-Type', 'application/json')

    try:
        response = urllib.request.urlopen(request, 
data=json_body.encode('utf-8'))
    except urllib.error.HTTPError as http_error:
        print(http_error)
        raw_data = http_error.read()
        print(raw_data)
        error_msg = raw_data.decode()
        print(error_msg)

I’m still trying to understand any edge cases/nuances, so the 200 is 
probably a bit ‘safer’.
rich

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-development/45b3404d-7d3a-4e64-82bc-8cf97ff16959n%40googlegroups.com.

Reply via email to