praw-dev/asyncpraw

subreddit.submit flair_text, flair_id returns 400 error if used.

xCROv opened this issue · 9 comments

xCROv commented

Describe the bug
When attempting to use attributes "flair_text" or "flair_id" reddit returns "received 400 HTTP response". This was done under a moderator account. Was not tested on a non-moderator account. Works fine with removal of these attributes and then using submission.mod.flair() to flair these posts under the same account with the same text.

To Reproduce
Steps to reproduce the behavior:

  1. Submit post to subreddit you moderator with "flair_text" or "flair_id" used. In the example "flair_text="FlairText"" was used.

Expected behavior
Submission of post using flair_text and flair_id given.

Code/Logs

subreddit = await reddit.subreddit("YourSubredditHere")
await subreddit.submit(title="Test Post", selftext="Test Post Body", flair_text="FlairText"))

System Info

  • OS: Windows
  • Python: 3.7.8
  • Async PRAW Version: asyncpraw 7.1.1.dev0
    asyncprawcore 1.5.1

I have the same error when testing this.

However if I include the flair_id parameter when submitting, it does not throw an error. It seems that when submitting a submission with a flair, flair_id is required at the minimum.

xCROv commented

When testing with just a flair_id= attribute I am getting the same 400 error. It appears if either is used the request is not processed. When looking at the actual request that is being sent I am not seeing any malformed information but I have not looked at what the API expects yet to validate.

Verified working values replaced with safe ones.


[ DEBUG ] -- Using selector: SelectSelector
c:\.Scripts\script\script.py:47: DeprecationWarning: Reddit will check for validation on all posts around May-June 2020. It is recommended to check for validation by setting reddit.validate_on_submit to True.
 await subreddit.submit(title="Title", selftext="Test Post\n\n[View Poll](https://www.reddit.com/poll/12345)", flair_id="VALID_FLAIR_ID_HERE")
[ DEBUG ] -- Fetching: POST https://oauth.reddit.com/api/submit/
[ DEBUG ] -- Data: [('api_type', 'json'), ('flair_id', 'VALID_FLAIR_ID_HERE'), ('kind', 'self'), ('nsfw', False), ('resubmit', True), ('sendreplies', True), ('spoiler', False), ('sr', 'SUBREDDIT_HERE'), ('text', 'Test Post\n\n[View Poll](https://www.reddit.com/poll/12345)'), ('title', 'Drama'), ('validate_on_submit', False)]
[ DEBUG ] -- Params: {'raw_json': 1}
[ DEBUG ] -- Response: 400 (40 bytes)

When I run the test here:

@mock.patch("asyncio.sleep", return_value=None)
async def test_submit__flair(self, _):
flair_id = "94f13282-e2e8-11e8-8291-0eae4e167256"
flair_text = "AF"
flair_class = ""
self.reddit.read_only = False
with self.use_cassette():
subreddit = await self.reddit.subreddit(pytest.placeholders.test_subreddit)
submission = await subreddit.submit(
"Test Title",
selftext="Test text.",
flair_id=flair_id,
flair_text=flair_text,
)
await submission.load()
assert submission.link_flair_css_class == flair_class
assert submission.link_flair_text == flair_text

with a valid flair_id and without flair_text, I don't get a 400 error. Are you sure your flair_id is valid? If it isn't, it will raise a 400 error.

xCROv commented

It looks like you are correct. In my instance I had set this to run against a test subreddit which caused it to run with an invalid flair_id for that subreddit. It looks like maybe the flair_id and flair_text pairing is just an undocumented api requirement like you had mentioned earlier.

It might be good to document that flair_id is required when submitting with a flair. Would you like to open a PR and add that to the documentation?

xCROv commented

When going to make the change I noticed that this is probably something that will affect all submit functions. If a maintainer feels like that's an appropriate addition it should probably be added. I have not tested it as of yet with the other types to be sure.

#72 Created

I feel that is an appropriate addition.

xCROv commented

I have updated the PR to reflect changes to the other submit functions.

Thank you! I left a review.