AnsweredAssumed Answered

Python API courses batch_update, doesn't work for 500 courses

Question asked by Ember Ludwig on May 6, 2020
Latest reply on May 7, 2020 by Ember Ludwig

I wrote a Python script to publish a large group of courses at one time using the API for Update courses (https://canvas.instructure.com/doc/api/courses.html#method.courses.batch_update).  

 

What I originally wrote was very similar to Mike Nahmias’ post (https://community.canvaslms.com/message/109721-python-script-to-publish-courses-in-an-account).  

 

However, it only works for about 350 courses while the limit is listed as 500.  I get a 414 error back instead of 200, because the URL is too long.  Here’s the full error:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>414 Request-URI Too Long</title>
</head><body>
<h1>Request-URI Too Long</h1>
<p>The requested URL's length exceeds the capacity
limit for this server.<br />
</p>
<hr>
<address>Apache Server at canvas.instructure.com Port 80</address>
</body></html>

Like Mike, I was using the “requests.put”:
    requests.put(url, headers=headers, params=payload)

 

So, that explains the error as everything is being put onto the URL and it’s just too long.  

 

However, when I switch it to use post, it no longer works.  Instead it creates a new course, as do all of these:
    requests.post(url, headers=headers, params=payload)
    requests.post(url, headers=headers, json=payload)
    requests.post(url, headers=headers, json=json.dumps(payload))

 

(Thanks to Brian Bennett’s reply and Jason Kocur’s thread for the json ideas, but it doesn’t work for this API.
https://community.canvaslms.com/thread/40398-canvas-apipython-help-post-requests)

 

Has anybody gotten this to work for > 350 courses?  And what’s the secret?

 

I’d be happy to try UCF Open’s canvasapi, but I can’t find this batch update for courses.

 

Thanks!
Ember

Outcomes