marasolen / md2canvas

Convert MyST markdown to Canvas quizzes.
2 stars 4 forks source link

Configparser error #8

Closed firasm closed 4 years ago

firasm commented 4 years ago

I just tried running md2canvas, but I ran into an error:

The command I ran was:

md2canvas -t <RedactedCanvasToken> -c 45445 ~/Sync/Teaching/utilities/md2canvas/examples/sample_quiz/SampleQuiz.md

The error I got was:

Traceback (most recent call last):
  File "/Users/firasm/.pyenv/versions/3.8.3/bin/md2canvas", line 8, in <module>
    sys.exit(md2canvas())
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/md2canvas/command.py", line 84, in md2canvas
    url = config.get("settings", "url")
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/configparser.py", line 781, in get
    d = self._unify_values(section, vars)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/configparser.py", line 1149, in _unify_values
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'settings'

Haven't had a chance to debug this yet... let me know if you have any ideas.

marasolen commented 4 years ago

What OS are you on? I have only tested on Windows.

You didn't provide the program a Canvas URL, so it tried to check the settings (md2canvas/config.ini) but didn't find a section called settings. I just tried cloning and running it fresh and didn't get this (even without supplying a URL).

firasm commented 4 years ago

I'm on macOS 10.15.6.

Ah, missing -u flag was my bad! New error now.

Relevant traceback:

Uploading quiz to Canvas with following settings:
  URL = https://canvas.ubc.ca/courses/45445
  Token = 1122**************************************************************cUgE
  Course ID = 45445
Traceback (most recent call last):
  File "/Users/firasm/.pyenv/versions/3.8.3/bin/md2canvas", line 8, in <module>
    sys.exit(md2canvas())
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/md2canvas/command.py", line 115, in md2canvas
    j2c.upload_quiz(quiz, url, token, course_id)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/md2canvas/json2canvas.py", line 197, in upload_quiz
    canvas_course = get_course(url, token, course_id)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/md2canvas/json2canvas.py", line 141, in get_course
    return canvas.get_course(course_id)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/canvasapi/canvas.py", line 638, in get_course
    response = self.__requester.request(
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/canvasapi/requester.py", line 242, in request
    raise ResourceDoesNotExist("Not Found")
canvasapi.exceptions.ResourceDoesNotExist: Not Found

Do I need to have the quiz created already in Canvas with the same name?

Full result

``` Parsing the quiz at /Users/firasm/Sync/Teaching/utilities/md2canvas/examples/sample_quiz/SampleQuiz.md WARNING: File Upload questions do not work in preview mode. WARNING: API does not support true/false questions, converting to multiple choice { "attrs": { "description": "

Test Canvas Quiz

\n

A test quiz with all supported question types and some sample metadata.

\n

Part of this github.

\n

Here is a picture of a flower:

\n

\"flower

", "image_paths": [ { "name": "media/flower.jpg", "path": "/Users/firasm/Sync/Teaching/utilities/md2canvas/examples/sample_quiz/media/flower.jpg" } ], "title": "Test Canvas Quiz", "allowed_attempts": 3, "scoring_policy": "keep_highest", "cant_go_back": false, "shuffle_answers": false }, "groups": [ { "attrs": { "name": "general" }, "questions": [ { "question_name": "1", "question_type": "essay_question", "points_possible": 5, "answers": [], "question_text": "

Question 1

\n

Write your name here!

", "image_paths": [] }, { "question_name": "2", "question_type": "file_upload_question", "points_possible": 1, "answers": [], "question_text": "

Question 2

\n

Upload a file, any file (note this will not work in preview mode)!

", "image_paths": [] }, { "question_name": "3", "question_type": "matching_question", "points_possible": 1, "answers": [ { "answer_match_left": "a", "answer_match_right": "a" }, { "answer_match_left": "b", "answer_match_right": "b" }, { "answer_match_left": "c", "answer_match_right": "c" }, { "answer_match_left": "d", "answer_match_right": "d" } ], "question_text": "

Question 3

\n

Match the same letters to each other.

\n

Left

\n
    \n
  • a
  • \n
  • b
  • \n
  • c
  • \n
  • d
  • \n
\n

Right

\n
    \n
  • a
  • \n
  • b
  • \n
  • c
  • \n
  • d
  • \n
  • e
  • \n
  • f
  • \n
", "matching_answer_incorrect_matches": "e\nf", "image_paths": [] }, { "question_name": "4", "question_type": "multiple_answers_question", "points_possible": 1, "answers": [ { "answer_text": "1", "answer_weight": 100 }, { "answer_text": "2", "answer_weight": 0 }, { "answer_text": "3", "answer_weight": 100 }, { "answer_text": "4", "answer_weight": 0 }, { "answer_text": "5", "answer_weight": 100 } ], "question_text": "

Question 4

\n

Choose the odd numbers.

\n
    \n
  • 1
  • \n
  • 2
  • \n
  • 3
  • \n
  • 4
  • \n
  • 5
  • \n
", "image_paths": [] }, { "question_name": "5", "question_type": "multiple_choice_question", "points_possible": 1, "answers": [ { "answer_text": "Not this one", "answer_weight": 0 }, { "answer_text": "This one", "answer_weight": 100 }, { "answer_text": "Not this one either", "answer_weight": 0 }, { "answer_text": "All of the above", "answer_weight": 0 } ], "question_text": "

Question 5

\n

What is the correct answer?

\n
    \n
  • Not this one
  • \n
  • This one
  • \n
  • Not this one either
  • \n
  • All of the above
  • \n
", "image_paths": [] }, { "question_name": "6", "question_type": "short_answer_question", "points_possible": 1, "answers": [ { "answer_text": "something" }, { "answer_text": "nothing" } ], "question_text": "

Question 6

\n

Type \"something\" or \"nothing\".

", "image_paths": [] }, { "question_name": "7", "question_type": "text_only_question", "points_possible": 1, "answers": [], "question_text": "

Question 7

\n

Take a break!

", "image_paths": [] }, { "question_name": "8", "question_type": "true_false_question", "points_possible": 1, "answers": [ { "answer_text": "True", "answer_weight": 100 }, { "answer_text": "False", "answer_weight": 0 } ], "question_text": "

Question 8

\n

Write true to get full marks.

", "image_paths": [] } ] }, { "attrs": { "name": "numerical questions", "pick_count": 1, "question_points": 3, "quesnum": 1 }, "questions": [ { "question_name": "9", "question_type": "numerical_question", "points_possible": 1, "answers": [ { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "exact_answer", "answer_exact": 4.0, "answer_error_margin": 0 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "exact_answer", "answer_exact": 4.0, "answer_error_margin": 0.1 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "exact_answer", "answer_exact": 4.0, "answer_error_margin": 0.1 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "range_answer", "answer_range_start": 3.9, "answer_range_end": 4.1 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "precision_answer", "answer_approximate": 4.0, "answer_precision": 2.0 } ], "question_text": "

Question 9a

\n

What is \"Latex:?

", "image_paths": [] }, { "question_name": "10", "question_type": "numerical_question", "points_possible": 1, "answers": [ { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "exact_answer", "answer_exact": 5.0, "answer_error_margin": 0 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "exact_answer", "answer_exact": 5.0, "answer_error_margin": 0.1 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "exact_answer", "answer_exact": 5.0, "answer_error_margin": 0.1 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "range_answer", "answer_range_start": 4.9, "answer_range_end": 5.1 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "precision_answer", "answer_approximate": 5.0, "answer_precision": 2.0 } ], "question_text": "

Question 9b

\n

What is \"Latex:?

", "image_paths": [] }, { "question_name": "11", "question_type": "numerical_question", "points_possible": 1, "answers": [ { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "exact_answer", "answer_exact": 6.0, "answer_error_margin": 0 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "exact_answer", "answer_exact": 6.0, "answer_error_margin": 0.1 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "exact_answer", "answer_exact": 6.0, "answer_error_margin": 0.1 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "range_answer", "answer_range_start": 5.9, "answer_range_end": 6.1 }, { "answer_text": "", "answer_weight": 100, "numerical_answer_type": "precision_answer", "answer_approximate": 6.0, "answer_precision": 2.0 } ], "question_text": "

Question 9c

\n

Evaluate the following expression.

\"Latex:

", "image_paths": [] } ] } ] } Uploading quiz to Canvas with following settings: URL = https://canvas.ubc.ca/courses/45445 Token = 1122**************************************************************cUgE Course ID = 45445 Traceback (most recent call last): File "/Users/firasm/.pyenv/versions/3.8.3/bin/md2canvas", line 8, in sys.exit(md2canvas()) File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 829, in __call__ return self.main(*args, **kwargs) File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs) File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/md2canvas/command.py", line 115, in md2canvas j2c.upload_quiz(quiz, url, token, course_id) File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/md2canvas/json2canvas.py", line 197, in upload_quiz canvas_course = get_course(url, token, course_id) File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/md2canvas/json2canvas.py", line 141, in get_course return canvas.get_course(course_id) File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/canvasapi/canvas.py", line 638, in get_course response = self.__requester.request( File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/canvasapi/requester.py", line 242, in request raise ResourceDoesNotExist("Not Found") canvasapi.exceptions.ResourceDoesNotExist: Not Found ```
marasolen commented 4 years ago

It should be able to create an entirely new quiz. It will only attempt to update an existing quiz if you give it a quiz ID. It looks like it failed to get the course, are you sure that the course ID you used is correct?

firasm commented 4 years ago

Hmm - yea, looks correct to me (screenshot below): 45445

Screen Shot 2020-08-06 at 6 32 05 PM

marasolen commented 4 years ago

Oops I missed it in your previous comment, the URL shouldn't include the course, just https://canvas.ubc.ca

firasm commented 4 years ago

aha! That worked!!

Thank you, I will update my instructions in #9