Hi
I can get a URL for a error report. the url likes this
https://domain/files/userid/errors2018-10-13+04%3A34%3A03+UTC20181013-17095-16eso8l.csv
How can I read this csv in python. Can I use request too?
thanks
li
These error reports? Error Reports - Canvas LMS REST API Documentation
What process is generating this file, or where is the error report coming from?
Hi Robert,
i use this https://domain/api/v1/accounts/account_id/sis_imports
from there I can find 'url' for downloading the report , for example, the url can be
https://domain/files/userid/download?11330000005243390_processing_warnings_and_errors2018-10-13+04%3A34%3A03+UTC20181013-17095-16eso8l.csv
I want to open this csv, and read data from it.
I use python. Hope this helps
julielkz, I'm not certain, but I don't think you can read the file without first downloading it.
You should be able to do that like this, including your token as carroll-ccsd indicated:
auth_header <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">'Authorization'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Bearer {}'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>token<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN><BR />content <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>file_url<SPAN class="punctuation token">,</SPAN> headers<SPAN class="operator token">=</SPAN>auth_header<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>content<BR /><SPAN class="keyword token">with</SPAN> open<SPAN class="punctuation token">(</SPAN>output_file_name<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'wb'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> file<SPAN class="punctuation token">:</SPAN><BR /> file<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN>content<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I was able to read the report CSVs without saving them to a file. Here's what I did:
<SPAN class="keyword token">import</SPAN> csv<BR /><SPAN class="keyword token">import</SPAN> io<BR /><BR /><SPAN class="keyword token">import</SPAN> requests<BR /><BR /><BR /><SPAN class="comment token"># Assuming you already got the download link from somewhere else</SPAN><BR />download_link <SPAN class="operator token">=</SPAN> <SPAN class="string token">'asdf'</SPAN><BR /><BR /><SPAN class="comment token"># The download link saves the CSV into memory</SPAN><BR />response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>url<SPAN class="operator token">=</SPAN>download_link<SPAN class="punctuation token">)</SPAN><BR /><SPAN class="comment token"># Raise errors if any occurred</SPAN><BR />response<SPAN class="punctuation token">.</SPAN>raise_for_status<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><BR /><BR /><SPAN class="comment token"># Use StringIO to process the CSV contents since we're not working with a file</SPAN><BR /><SPAN class="comment token"># Cast the DictReader as a list so you can iterate over it more than once</SPAN><BR />data <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN>csv<SPAN class="punctuation token">.</SPAN>DictReader<SPAN class="punctuation token">(</SPAN>io<SPAN class="punctuation token">.</SPAN>StringIO<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Canvas Data Services sent out an alert that a course was concluded (because the course was concluded) and the status of each user in the UI is set to complete, however, the enrollments API endpoint shows the status of each user in the course as active. Is this a common issue? Have I misinterpreted how the individual…
How can one track Canvas Media use without having the reports available from Canvas Studio? Checking API endpoints and the Data 2 schema, there do not seem to be dedicated Canvas Media endpoints. Am I missing some? A method I've considered is using the body field of the wiki_pages table, as this contains the html code of…
Hello, I'm trying to utilize an API call to pull completed certificates and was hoping to download and store the certs as a backup. I can successfully run the API call but it will not allow me to view the certificate unless I access the URL while signed into an account where it's "my" cert. Is there a permissions setting…
UI for weekly progression idea that rest in the Schedule tab of the **K-12 UI** of Canvas it's incomplete and I really would not take it and push it into instance but I am going to post it here because in the past people like @James && @robotcars || @Steve_25 have had terrific input in the past... maybe w/their eyes and…
I have a new React + Flask webapp. It has its own login for users to start using the app. I have added this as an external tool in Canvas. What I want initially is to see of canvas users can start using the webapp without having to login if they click on the external tool link in a canvas course. I have 2 methods…