以编程方式将文件附加到Desie2Learning Dropbox feedb

2024-09-28 12:14:44 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是我对将文件上载到实体的dropbox提交时所需操作顺序的理解:

  1. 为用户创建反馈(在我的例子中,我自动填充一个评估准则)
  2. 上载文件,接收唯一的文件密钥
  3. 使用(2)中收到的密钥将该文件附加到用户的反馈中

我可以使用web界面为用户上传一个文件到d2L,但显然,如果我是通过自动化准备反馈的话,显然想简化这一点。我现在的状态是:

  1. 为用户创建反馈(在我的例子中,我自动填充一个评估准则)(200-成功)
  2. 上载文件,接收唯一的文件密钥(200-成功)
  3. 使用(2)中收到的密钥将该文件附加到用户的反馈中(404-未找到)

我一直在努力如何调试上传和附加一个文件到dropbox反馈。我遵循了http://docs.valence.desire2learn.com/basic/fileupload.html#resumable-uploads上的可恢复上传指令,并且(通常)一切正常,但是当我将上传的文件附加到这个实体的dropbox文件夹时,我得到了最后一个404错误。在

下面是我的调试输出,它演示了我所理解的系统状态。在

注意:我在外部编辑器中使用search and replace替换了COURSEID、DROPBOXID、ENTITYID和一些键,以保持安全性。

POST /d2l/api/le/1.4/COURSEID/dropbox/folders/DROPBOXID/feedback/user/ENTITYID

将此用户的反馈发布到dropbox

^{2}$

确认发布成功

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命令总是失败的,因为我必须在第一个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,但没有其他版本。在

我还强制将反馈标记为feedback['IsGraded']=False,以防由于某些原因,如果反馈已发布,则无法向反馈添加文件。然后我重新发布反馈(在将其标记为未分级后),并尝试将上载的文件附加到该反馈中。另外一个变量是,我也尝试(并删除)post使用fileName参数(在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管理员没有带宽来支持我,而且我不确定是否可以访问日志,所以我不知道如何改进我这边的调试。提前谢谢!在


Tags: 文件用户leapifeedbackfoldersfiledropbox

热门问题