[API] Error 500: The software powering this discussion forum encountered an unexpected problem


(Bryan Underwood) #1

When creating new topics via the API, I am suddenly getting this error. It’s been working fine all morning. I am sure it’s not related to rate limiting because that is not the error message. Also, I have a 2 second sleep between API commands.

I can create posts just fine, but when I try to create a post as a new topic with the following parameters it fails:

api_key = $AUTH_APIKEY
api_username = $AUTH_USERNAME
title = "my topic title"
raw = "my post text"
category = 0
created_at = "1/27/2017 15:41"

Also, this only just started happening. I have been creating Topics and Posts all morning with my API script.

Anyone got a clue?


(Blake Erickson) #2

I’m really not sure. You might need to go to /logs and see if you can see a better error message with a little bit more detail. It could not like the title or the body of the post or any number of things, but I think those wouldn’t throw a 500. It could be overloading your db and server especially if you have sidekiq running as well.

Is there reason why you are creating a posts/topics every 2 seconds via the api? Maybe it would be better to write an import script and run it on the server with sidekiq off.


(Bryan Underwood) #3

Thanks, Blake. My log has this:

ArgumentError (argument out of range) /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/values/time_zone.rb:528:ininitialize’`

I don’t think the rest of the log details are relevant, and it is quite lengthy.

Regarding the 2-second timing… I am trying to avoid a hard rate limit, even though I have set my limits to 0 seconds under Admin. Using the API is super convenient, but it is getting painful. I have a flat file with all of the data to import. My users are already staged and I am importing 2,000+ topics and 14,000+ posts. I think I need to just follow the docs for writing an import script.

FWIW, I am using PowerShell and monitoring the API output as I go. I have discovered all of the limitations like min/max char. limits, etc. So it has been helpful. But again, it seems to me an import script would be faster.

Any suggestions on where to start? Another user suggested starting with the PhpBB3 script and going from there. I would like to avoid setting up a local server, etc. as @pfaffman and others suggest. My environment is still pre-production so I am not concerned users seeing it as it goes along.


(Bryan Underwood) #4

I went back and looked at the API docs – the /post endpoint wants the post date in the format like

yyyy-MM-dd HH:mm

Once I updated my script to use that format, everything started working again. The mystery is why similar dates worked up until now. Anyway, thanks for your help Blake.


(Blake Erickson) #5

I don’t think it likes your created_at value:

blake@dev ~/code/discourse_api_sandbox (master) $ ruby new_topics.rb
/home/blake/.rvm/gems/ruby-2.4.2/gems/discourse_api-0.20.0/lib/discourse_api/client.rb:141:in `handle_error': ArgumentError at /posts (DiscourseApi::Error)
=======================

> argument out of range

lib/topic_creator.rb, line 126
------------------------------

``` ruby
  121
  122       @guardian.ensure_can_create!(Topic, category) unless (@opts[:skip_validations] || @opts[:archetype] == Archetype.private_message)
  123
  124       topic_params[:category_id] = category.id if category.present?
  125
> 126       topic_params[:created_at] = Time.zone.parse(@opts[:created_at].to_s) if @opts[:created_at].present?
  127
  128       topic_params[:pinned_at] = Time.zone.parse(@opts[:pinned_at].to_s) if @opts[:pinned_at].present?
  129       topic_params[:pinned_globally] = @opts[:pinned_globally] if @opts[:pinned_globally].present?
  130
  131       if SiteSetting.topic_featured_link_enabled && @opts[:featured_link].present? && @guardian.can_edit_featured_link?(topic_params[:category_id])
```