These are chat archives for praw-dev/praw

17th
Mar 2018
Joe RH
@jarhill0
Mar 17 03:22
@bboe Any idea what parameters will be returned in a 415 response? I'm trying to add #65 but I don't know what the response from Reddit will look like since it seems to only happen on certain accounts (see https://redd.it/849uby)
Actually, per the issue, I might be able to reproduce a 415 with bad css. I'll try that.
Bryce Boe
@bboe
Mar 17 03:41
Yeah, bad css was the way I was thinking of going.
Or bad automod config.
Joe RH
@jarhill0
Mar 17 03:41
Unfortunately I couldn't get bad CSS to give me a 415, so I'm trying bad automod
Bryce Boe
@bboe
Mar 17 03:42
Interesting.
What did it result in?
Joe RH
@jarhill0
Mar 17 03:42
got it with automod
Bryce Boe
@bboe
Mar 17 03:42
Sweet.
Joe RH
@jarhill0
Mar 17 03:42
the bad CSS led to an APIException — there was an error returned in the response
APIException: BAD_CSS: 'invalid css' on field 'stylesheet_contents'
Bryce Boe
@bboe
Mar 17 03:42
Interesting. When you did it through the wiki?
Joe RH
@jarhill0
Mar 17 03:43
No, I did it through stylesheet.update(). That may be why I didn't get the 415
Bryce Boe
@bboe
Mar 17 03:43
Yeah, I think it's unique to setting css through the wiki.
Joe RH
@jarhill0
Mar 17 03:46
Thanks — that makes sense
Bryce Boe
@bboe
Mar 17 03:48
Thank you.
Joe RH
@jarhill0
Mar 17 03:59

Question about implementation @bboe: I'm parsing the messages returned in the response, but to do that, I have to parse the JSON. On the off-chance that the JSON, is invalid, this is what I have:

try:
    resp_dict = self.response.json()
except ValueError:
    self.message = ''
    self.special_errors = []
else:
    self.message = resp_dict.get('message', '')
    self.special_errors = resp_dict.get('special_errors', [])

It looks nicer without the try-except, but I think it's probably necessary. What are your thoughts?

Bryce Boe
@bboe
Mar 17 04:01
I think it's safe to assume the json is valid.
Joe RH
@jarhill0
Mar 17 04:01
Alright, thanks.
Bryce Boe
@bboe
Mar 17 04:01
Right now it's raising an assertion error, having invalid JSON will give another exception, but I think that's fine.
Then we'll have data to prove to us what we need to do.
Joe RH
@jarhill0
Mar 17 04:09

Another question: Which parts of the response should be in the text of the exception that is raised? As a sample, here's one response I get:

{'message': 'Unsupported Media Type',
 'reason': 'SPECIAL_ERRORS',
 'special_errors': ['invalid value for `action`: `upvote` in rule:\n'
                    '\n'
                    'type: submission\n'
                    'action: upvote']}

special_errors seems to be the most useful, but since it's a list I'm concerned it might contain more information than needed and be overwhelming.

I'm not sure if reason or message every vary, so they might not be useful.

I'm leaning towards ' '.join(repr(err) for err in resp_dict['special_errors']) but I'd like to hear what you think.

Thanks :)
Bryce Boe
@bboe
Mar 17 04:10
Yeah, I'd suggest putting in special_errors.
Or maybe just message, and people can pull the full message out of the exception object since it contains the response.
Joe RH
@jarhill0
Mar 17 04:12
Any preference between message and reason? message seems to be just the name of the HTTP status code