首页 > 解决方案 > boto3 mturk:笑脸导致调用CreateHITWithHITType操作时发生错误(ParameterValidationError)

问题描述

使用 Python 3.7 和 boto3 在 MTurk 上创建 HIT,boto3 库崩溃并出现以下错误。我做了一些测试并得出结论,错误是由HITLayoutParameters字段中的“”字符引起的(见下文)。

如何在仍以原始形式上传文本的同时避免此问题?

hit_layout_id = 'XXXXM4PUG5TWD3TK4NDUWHRJUUXXXX'
hit_layout_params = [{'Name': 'text', 'Value': 'Listening and learning, but standing strong  pic.twitter.com/7TSroSf8h1 — Ilhan Omar (@IlhanMN) February 11, 2019\n<u><b>Omar</b></u> did not apologize, however, for another anti-Semitic comment she made in February, accusing pro-Israel Americans of having an “allegiance to a foreign country.”'}, {'Name': 'target', 'Value': 'Omar'}]
hit_type_id = 'XXXX7R2NRGZ96BC693FAIJ5481XXXX'
lifetime_in_seconds = 259200
num_max_assignments = 5

# boto3 client initialization
client = ...

# upload the hit
client.create_hit_with_hit_type(
    HITTypeId=hit_type_id,
    MaxAssignments=num_max_assignments,
    LifetimeInSeconds=lifetime_in_seconds,
    RequesterAnnotation=requester_annotation,
    HITLayoutId=hit_layout_id,
    HITLayoutParameters=hit_layout_params,
)

标签: python-3.xboto3

解决方案


那是一个编码问题。可以在您的应用程序中将您的文本编码为支持的编码并在您要使用它时对其进行解码?


推荐阅读