在将文件上传到实体的保管箱提交时,我了解了所需的操作顺序:
我可以使用网络界面为用户上传一个文件到d2L,但显然我想简化这个,如果我正在通过自动化准备反馈。我目前的状态是:
我一直在努力调试如何调试上传并将文件附加到Dropbox反馈。我按照http://docs.valence.desire2learn.com/basic/fileupload.html#resumable-uploads上的可恢复上传说明进行了操作,并且(通常)一切正常,但是当将上传的文件附加到此实体的Dropbox文件夹时,我收到了最终的404错误。
下面是我的调试输出,它向我展示了我理解的系统状态。
注意:我在外部编辑器中使用搜索和替换替换了COURSEID,DROPBOXID,ENTITYID和一些键,以保持安全的假象。
POST /d2l/api/le/1.4/COURSEID/dropbox/folders/DROPBOXID/feedback/user/ENTITYID
将反馈发布到此用户的Dropbox
{}
确认帖子成功
filepath=092215-0952/Testing Download Sep 21, 2015 1114 AM_upload/ENTITYID-DROPBOXID - Student Name-Due 18, YYYY TIME AM - netid_assignmentname.zip_upload.zip
length=76630
https://d2l.domain.tld/d2l/api/le/1.4/COURSEID/dropbox/folders/DROPBOXID/feedback/user/ENTITYID/upload?x_b=_________USERID___________&x_c=_________KEY_I_DONT_UNDERSTAND___________&x_a=_________APP_ID___________&x_d=_________ANOTHER_KEY_I_DONT_UNDERSTAND___________&x_t=1443053113
{'Content-Length': '76630', 'User-Agent': 'python-requests/2.7.0 CPython/3.3.6 Darwin/14.5.0', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'keep-alive', 'Accept': '*/*', 'X-Upload-Content-Type': 'application/zip', 'X-Upload-File-Name': 'temp.zip', 'X-Upload-Content-Length': '76630'}
Received new URL to which to upload this file: revising post for this fileKey
result=qafSoMUYAm
https://d2l.domain.tld/d2l/upload/qafSoMUYAm
result of revised post is 200
有了这个,似乎我启动并完成了可恢复的上传。我会说,这个部分通过valence的指令变得更容易了,但是在我尝试调试它之前有很多嘀咕,直到我意识到d2lservice中的一些内置post命令总是会失败,因为我不得不在第一篇文章后更改URL。 :)顺便说一下,如果我故意弄乱文件长度的字节数,我可以使它返回416。我这样做是为了确保我没有因为错误的原因而得到200.
fileKey=qafSoMUYAm, attaching to the dropbox now
GET /d2l/api/le/1.1/COURSEID/dropbox/folders/DROPBOXID/feedback/user/ENTITYID
Feedback exists for org_unit_id=COURSEID,folder_id=DROPBOXID,entity_id=ENTITYID
在这里,我确保该用户确实存在反馈,因此我可以将URL与下面失败的URL进行比较。注意:我几乎使用1.4版本,但在下面的示例中,我将版本硬编码为1.1,以防API中存在版本差异;我试过1.1,1.4,但没有别的。
我也强制将反馈标记为反馈[' IsGraded'] = False,如果出于某种原因,如果反馈已被反馈,则无法将文件添加到反馈中出版。然后我重新发布反馈(在将其标记为未评级后),并尝试将上传的文件附加到此反馈。另一个变量是我也尝试(并删除)使用fileName param作为帖子(它在API中列为可选项)。
POST /d2l/api/le/1.4/COURSEID/dropbox/folders/DROPBOXID/feedback/user/ENTITYID
I am turning on debug now...
ready for POST=/d2l/api/le/1.1/COURSEID/dropbox/folders/DROPBOXID/feedback/user/ENTITYID/attach
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): d2l.domain.tld
send: b'POST /d2l/api/le/1.1/COURSEID/dropbox/folders/DROPBOXID/feedback/user/ENTITYID/attach?fileKey=qafSoMUYAm&x_b=_________USERID___________&x_a=_________APP_ID___________&x_d=sw6PXGCvBOsBj07VJCPu4RJ6hN8AN7OIId2ONOj-_CA&x_t=1443053116&x_c=LIrzfSOnb8rz3wkN-ZTbfnckwvrfheUU9kkarOhGpok HTTP/1.1\r\nHost: d2l.domain.tld\r\nConnection: keep-alive\r\nUser-Agent: python-requests/2.7.0 CPython/3.3.6 Darwin/14.5.0\r\nContent-Length: 0\r\nAccept: */*\r\nAccept-Encoding: gzip, deflate\r\n\r\n'
reply: 'HTTP/1.1 404 Not Found\r\n'
DEBUG:requests.packages.urllib3.connectionpool:"POST /d2l/api/le/1.1/COURSEID/dropbox/folders/DROPBOXID/feedback/user/ENTITYID/attach?fileKey=qafSoMUYAm&x_b=_________USERID___________&x_a=_________APP_ID___________&x_d=sw6PXGCvBOsBj07VJCPu4RJ6hN8AN7OIId2ONOj-_CA&x_t=1443053116&x_c=LIrzfSOnb8rz3wkN-ZTbfnckwvrfheUU9kkarOhGpok HTTP/1.1" 404 0
所以,我在尝试撰写这篇文章时得到了404,以及Python下面的一些错误,这些错误并不是真的有帮助(但无论如何我都包括它们)。
header: Server header: X-XSS-Protection header: X-UA-Compatible header: X-Powered-By header: Date header: Content-Length header: Set-Cookie <Response [404]>
Traceback (most recent call last):
File "../valence/sprinkle/production/postgradenoui.py", line 239, in <module>
print(postGrades_handler(dropboxid, gradeddirname,gradeddir_uploadname))
File "../valence/sprinkle/production/postgradenoui.py", line 230, in postGrades_handler
result = sprinkleutil.postRubricFeedback(request, _ac, dropboxid, gradeddirname, _CFG_COURSE['courseorgunit'], gradeddir_uploadname)
File "/Users/sprinkle/work/teaching/ece275-2015F/grading/valence/sprinkle/production/sprinkleutil.py", line 1279, in postRubricFeedback
upload_feedback_files_for_dropbox_feedback(uc,orgunitNeeded,dropboxNeeded,dir,dbfFile,'1.4')
File "/Users/sprinkle/work/teaching/ece275-2015F/grading/valence/sprinkle/production/sprinkleutil.py", line 791, in upload_feedback_files_for_dropbox_feedback
result = attach_uploaded_file(uc,org_unit_id,folder_id,entity_id,fileKey,'temp.zip')
File "/Users/sprinkle/work/teaching/ece275-2015F/grading/valence/sprinkle/production/sprinkleutil.py", line 523, in attach_uploaded_file
return d2lservice._fetch_content(r)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/d2lvalence_util/service.py", line 46, in _fetch_content
r.raise_for_status()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/requests/models.py", line 851, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found
我很感激任何成功执行过这一系列操作的指针。我的d2l管理员没有带宽来支持我,而且我不确定我是否可以访问日志,因此我不知道如何改进我的调试。提前谢谢!
答案 0 :(得分:0)
对于您的附加阶段,您似乎在发送fileKey
作为查询参数。它需要是一个POST表单参数,对吗?
所以POST的内容类型为application/x-www-form-urlencoded
,POST主体本身就是
fileKey=qafSoMUYAm&fileName=SomeFileName.zip
例如,请参阅How to mimic an HTML form submission in a POST request。