简体   繁体   中英

Publishing my HTML into HIT in Mturk sandbox from my local conputer

I'm figuring out how I can publish my HTML file using python from my local computer to HITs in the sandbox. I have my python and HTML in the same directory and used the template in the given tutorial. https://docs.aws.amazon.com/AWSMechTurk/latest/AWSMechanicalTurkRequester/Welcome.html .


  

    1 import boto3
      2 MTURK_SANDBOX = 'https://mturk-requester-sandbox.us-east-1.amazonaws.com'
      3 mturk = boto3.client('mturk',
      4    aws_access_key_id = "AKIAWMEANKTGFT3M57VI",
      5    aws_secret_access_key = "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",
      6    region_name='us-east-1',
      7    endpoint_url = MTURK_SANDBOX
      8 )
      9 print("I have $" + mturk.get_account_balance()['AvailableBalance'] + " in my Sandbox account")
     10
     11 html_layout = open('./HTML_template.html', 'r').read()
     12 new_hit = mturk.create_hit(
     13     Title = 'Finish all tasks',
     14     Description = 'Please follow the instructions described in the webpage',
     15     Keywords = 'multiple choice',
     16     Reward = '0.01',
     17     MaxAssignments = 1,
     18     LifetimeInSeconds = 172800,
     19     AssignmentDurationInSeconds = 600,
     20     AutoApprovalDelayInSeconds = 14400,
     21     Question = html_layout,
     22 )
     23 print("A new HIT has been created. You can preview it here:" )
     24 print("https://workersandbox.mturk.com/mturk/preview?groupId=" + new_hit['HIT']['HITGroupId'])
     25 print("HITID = " + new_hit['HIT']['HITId'] + " (Use to Get Results)")
     26 # Remember to modify the URL above when you're publishing
     27 # HITs to the live marketplace.
     28 # Use: https://worker.mturk.com/mturk/preview?groupId=

 

Here is the error message when I run the command python3 create_tasks.py

botocore.exceptions.ClientError: An error occurred (ParameterValidationError) when calling the CreateHIT operation: There was an error parsing the XML question or answer data in your request.  Please make sure the data is well-formed and validates against the appropriate schema. Details: Scanner State 24 not Recognized  (1602359732641 s)

Here is my thought: There is a bug in line 11. The function open cannot accept HTML file and thus I got an error. How can I fix this bug?

What is the content of your HTML file?

It shouldn't be just HTML. Turk expects that html to be wrapped in an Tag.

See https://docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkAPI/ApiReference_HTMLQuestionArticle.html for an example and see how the html question is formatted.

It's very likely that your HTML file is not formatted properly. Please see the following example.



    
      
          
            
        <crowd-form>
          <crowd-classifier
            name="sentiment"
            categories="['Positive', 'Negative', 'Neutral', 'N/A']"
            header="What sentiment does this text convey?"
          >
            <classification-target>
            Everything is wonderful.
            </classification-target>
            
            <full-instructions header="Sentiment Analysis Instructions">
            <p><strong>Positive</strong> 
              sentiment include: joy, excitement, delight</p>
            <p><strong>Negative</strong> sentiment include: 
              anger, sarcasm, anxiety</p>
            <p><strong>Neutral</strong>: neither positive or 
              negative, such as stating a fact</p>
            <p><strong>N/A</strong>: when the text cannot be 
              understood</p>
            <p>When the sentiment is mixed, such as both joy and sadness,
              use your judgment to choose the stronger emotion.</p>
            </full-instructions>
         
            <short-instructions>
             Choose the primary sentiment that is expressed by the text. 
            </short-instructions>
          </crowd-classifier>
        </crowd-form>
      </body>
    </html>
  ]]></HTMLContent>
  <FrameHeight>0</FrameHeight>
</HTMLQuestion>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM