TypeError:open()缺少必需的参数'file'(位置1)

时间:2018-11-30 06:58:49

标签: python

我尝试使用python发布有关mturk的示例问题,因此我按照该教程进行操作并复制其代码,如下所示。但是,我总是收到类似以下错误:

我不知道...请帮助! 谢谢!

  

第22行中的文件“ C:/Users/jingh/Py​​charmProjects/test/example.py”          问题=打开(名称='questions.xml',模式='r')。read()         TypeError:open()缺少必需的参数“文件”(位置1)

     

以退出代码1完成的过程

question = open(name='questions.xml',mode='r').read()
new_hit = client.create_hit(
    Title = 'Is this Tweet happy, angry, excited, scared, annoyed or upset?',
    Description = 'Read this tweet and type out one word to describe the emotion of the person posting it: happy, angry, scared, annoyed or upset',
    Keywords = 'text, quick, labeling',
    Reward = '0.15',
    MaxAssignments = 1,
    LifetimeInSeconds = 172800,
    AssignmentDurationInSeconds = 600,
    AutoApprovalDelayInSeconds = 14400,
    Question = question,
)
print ("A new HIT has been created. You can preview it here:")
print ("https://workersandbox.mturk.com/mturk/preview?groupId=" + new_hit['HIT']['HITGroupId'])
print ("HITID = " + new_hit['HIT']['HITId'] + " (Use to Get Results)")
# Remember to modify the URL above when you're publishing
# HITs to the live marketplace.
# Use: https://worker.mturk.com/mturk/preview?groupId=

2 个答案:

答案 0 :(得分:0)

对Python open()函数的第一个争论是file。所以改变这个

question = open(name='questions.xml',mode='r').read()

question = open(file='questions.xml',mode='r').read()

或者简单地

question = open('questions.xml',mode='r').read()

答案 1 :(得分:0)

您还可以尝试:使用START RequestId: eb7906af-f46d-11e8-ae3b-45487c02a68e Version: $LATEST 2018-11-30T07:02:38.509Z eb7906af-f46d-11e8-ae3b-45487c02a68e TypeError: Cannot create property 'stack' on string 'Could not find ffmpeg executable, tried "/var/task/node_modules/@ffmpeg-installer/linux-x64/ffmpeg" and "/var/task/node_modules/@ffmpeg-installer/ffmpeg/node_modules/@ffmpeg-installer/linux-x64/ffmpeg"' END RequestId: eb7906af-f46d-11e8-ae3b-45487c02a68e REPORT RequestId: eb7906af-f46d-11e8-ae3b-45487c02a68e Duration: 38.73 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 19 MB RequestId: eb7906af-f46d-11e8-ae3b-45487c02a68e Process exited before completing request 关键字将文件正常关闭。从with

中拯救您
memory leak