我正在尝试自动填写一个表单(其中包括一个文件上传)使用机械。我已经在GUI界面中完成了这个过程,文件上传得很好,所以我知道文件没有损坏,但是当我运行我的机械化脚本时,它失败了。脚本执行正确,根据调试,它上传了文件,但Canvas (我上传到的服务)显示无法读取该文件。我已经联系了Canvas支持人员,但他们无法提供帮助,因为这是对他们系统的非标准使用。
以下是脚本(已被匿名):
09 mech = Mechanize.new
10 mech.log = Logger.new(STDOUT)
11 mech.user_agent_alias = 'Mac Mozilla'
12 mech.get("https://ucdenver.test.instructure.com") do |page|
13 page.form_with(:action => "/login") do |f|
14 user_field = f.field_with(:name => "pseudonym_session[unique_id]")
15 user_field.value = user
16 pwd_field = f.field_with(:name => "pseudonym_session[password]")
17 pwd_field.value = pwd
18 end.submit
19 end
20
21 mech.get("https://ucdenver.test.instructure.com/accounts/1") do |page|
22 page.form_with(:action => "/accounts/1/courses") do |f|
23 course_field = f.field_with(:name => "course[name]")
24 course_field.value = "38492"
25 end.submit
26 end
27
28 mech.page.link_with(:href => %r/settings/,
29 :class => "settings").click
30
31 mech.page.link_with(:href => %r/import/,
32 :text => %r/Import Content/).click
33
34 mech.page.link_with(:href => %r/imports\/migrate/,
35 :text => %r/Import content from a content package/).click
36
37 mech.page.form_with(:action => %r/imports\/migrate/) do |f|
38 export_system = "migration_settings[migration_type]"
39 f[export_system] = "blackboard_exporter"
40 f.file_uploads.first.mime_type = "application/zip"
41 f.file_uploads.first.file_name = bkb_export
42 end.submitCanvas支持人员说服务器正在返回:
Could not unzip archive file, exit status 9, message:
[/mnt/var/web/migration_tool/data/attachment_420130214-13303-sv6ue5-0.jpg] End-of-central-
directory signature not found. Either this file is not a zipfile, or it constitutes one
disk of a multi-part archive. In the latter case the central directory and zipfile comment
will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in
one of /mnt/var/web/migration_tool/data/attachment_420130214-13303-sv6ue5-0.jpg or
/mnt/var/web/migration_tool/data/attachment_420130214-13303-sv6ue5-0.jpg.zip, and cannot
find /mnt/var/web/migration_tool/data/attachment_420130214-13303-sv6ue5-0.jpg.ZIP, period.不幸的是,这个错误对我来说没有任何意义,但它在脚本上传.zip文件时引用了几个.jpg文件,这似乎很奇怪。任何想法或帮助都会非常感谢,如果我遗漏了任何有用的东西,我很乐意提供更多的信息。
如果你真的觉得自己是一个go getter,你可以在http://canvas.instructure.com注册一个免费帐户,自己看看代码/网络活动。
发布于 2014-09-11 20:56:10
确保您上传的文件具有正确的类型afaik ruby-mechanize指定
Content-Type: application/octet-stream对于每种类型的文件,很可能服务器正在检查ContentType,并且没有正确地匹配所需的内容类型,我不记得我使用的mechanize的确切版本,但对我来说,它是硬编码在mechanize gem中的,所以你必须通过mechanize的源代码并修复它是多部分/形式数据文件元素的硬编码内容类型。
https://stackoverflow.com/questions/14943482
复制相似问题