def _fault(code, msg): '''Generate fault XML''' faultcode = Element('faultcode').setText(code) faultstring = Element('faultstring').setText(msg) fault = Element('Fault').append([faultcode, faultstring]) body = Element('Body').append(fault) envelope = Element('Envelope', ns=soap_envns) envelope.append(body) envelope.refitPrefixes() return envelope.str()
answer_specification = Element('AnswerSpecification', ns=qfns) free_text_answer = Element('FreeTextAnswer', ns=qfns) constraints = Element('Constraints', ns=qfns) length = Element('Length', ns=qfns) length.set('minLength', '1') length.set('maxLength', '50') constraints.append(length) free_text_answer.append(constraints) answer_specification.append(free_text_answer) question_form_question.append(answer_specification) question_form.append(question_form_question) # end QuestionForm hit_request.Question = question_form.str() # str() to encode the xml # end HITRequest.Question # begin HITRequest.Reward reward_price = client.factory.create('Price') reward_price.CurrencyCode = 'USD' reward_price.Amount = 0.03 # 3 cents hit_request.Reward = reward_price # end HITRequest.Reward # end HITRequest # make the CreateHIT request try:
answer_specification = Element( 'AnswerSpecification', ns=qfns ) free_text_answer = Element( 'FreeTextAnswer', ns=qfns ) constraints = Element( 'Constraints', ns=qfns ) length = Element( 'Length', ns=qfns ) length.set( 'minLength', '1' ) length.set( 'maxLength', '50' ) constraints.append( length ) free_text_answer.append( constraints ) answer_specification.append( free_text_answer ) question_form_question.append( answer_specification ) question_form.append( question_form_question ) # end QuestionForm hit_request.Question = question_form.str() # str() to encode the xml # end HITRequest.Question # begin HITRequest.Reward reward_price = client.factory.create( 'Price' ) reward_price.CurrencyCode = 'USD' reward_price.Amount = 0.03 # 3 cents hit_request.Reward = reward_price # end HITRequest.Reward # end HITRequest # make the CreateHIT request try: