Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPError: 422 Client Error: Unprocessable Entity for url when Creating a Topic #9

Open
cod3r0k opened this issue Jul 11, 2020 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@cod3r0k
Copy link

cod3r0k commented Jul 11, 2020

Hi, I want to add some topics but the exception is occurring


~\Anaconda3\lib\site-packages\discourse\client.py in _request(self, method, path, params, data)
     29             data=data,
     30         )
---> 31         response.raise_for_status()
     32 
     33         return response.json()
~\Anaconda3\lib\site-packages\requests\models.py in raise_for_status(self)
    938 
    939         if http_error_msg:
--> 940             raise HTTPError(http_error_msg, response=self)
    941 
    942     def close(self):
HTTPError: 422 Client Error: Unprocessable Entity for url


image

@samamorgan
Copy link
Owner

Please share the code you're using to generate this topic, and the full traceback. I can't tell what's going on with the information presented.

@cod3r0k
Copy link
Author

cod3r0k commented Jul 14, 2020

Dear @samamorgan

try:
    mytopic = client.create_topic(
        title=topic_title,
        raw=topic_content,
        category=topic_category_id, 
        created_at=topic_time
    )
    time.sleep(1)       
    comments = item.topic_replies

    for item2 in comments:
        com_content = item2.reply_content
        com_usr = item2.reply_user
        com_time = item2.reply_time

        client.create_post(
            topic_id=mytopic.topic_id,
            raw=com_content
            created_at=com_time
        )
        time.sleep(1)
        
except:
    print('detect one problem')

In some cases it is going the exception section. When I check it, it returns that problem. I think maybe the URL is very long, but I don't know how to reduce it. (Maybe this could help us)

@samamorgan samamorgan changed the title HTTPError: 422 Client Error: Unprocessable Entity for url HTTPError: 422 Client Error: Unprocessable Entity for url when Creating a Topic Jul 14, 2020
@samamorgan samamorgan added the help wanted Extra attention is needed label Jul 14, 2020
@samamorgan
Copy link
Owner

What's the full traceback? Have you tried printing out the return message? I'd expect the API to return a useful message of some sort in addition to the URL. This library is built on Requests, so you can simply inspect the response object in the HTTPError that's being thrown to see what's going on.

I'd also suggest creating a topic with the bare-minimum amount of information as a first test, then slowly add more information until you hit a break. If you can find out more about what is causing this, this library can address it (or not, depending on the cause).

@cod3r0k
Copy link
Author

cod3r0k commented Jul 14, 2020

Thanks @samamorgan
As I mentioned in the first comment, the plain text of the request is depicted
image

@cod3r0k
Copy link
Author

cod3r0k commented Jul 14, 2020

I think when the topic content is so long, it occurs. But, my question is that, why it post to posts.json likes as GET method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants