Python 对具有不同JSON内容的URL的POST请求仅针对文件输入的最后一个值成功执行

Python 对具有不同JSON内容的URL的POST请求仅针对文件输入的最后一个值成功执行,python,json,Python,Json,我编写了一个python脚本,分别从文本文件中读取值,然后执行GET请求,从URI中获取每个值的数据。我正在对数据进行更改,并将数据发布到同一URI 然而,我在这里面临的问题是: 1.如果在输入文件中使用10个值,前9个值给出500服务器错误,最后一个值成功执行,响应为200 OK并成功更新数据。 2.当我删除最后一个值并再次运行它时,相同的重复8以500失败,1以200 OK成功。对于任意数量的值都会重复此操作。 3.脚本始终为一个输入值成功运行 请检查脚本和帮助 #!/usr/bin/pyt

我编写了一个python脚本,分别从文本文件中读取值,然后执行GET请求,从URI中获取每个值的数据。我正在对数据进行更改,并将数据发布到同一URI

然而,我在这里面临的问题是: 1.如果在输入文件中使用10个值,前9个值给出500服务器错误,最后一个值成功执行,响应为200 OK并成功更新数据。 2.当我删除最后一个值并再次运行它时,相同的重复8以500失败,1以200 OK成功。对于任意数量的值都会重复此操作。 3.脚本始终为一个输入值成功运行

请检查脚本和帮助

#!/usr/bin/python


import sys
import requests
import json

POSTAPI_PROD = URI here(not mentioned since public forum)
POSTAPI_HEADERS = headers here

#returns the POST response code for each value from payload data
def post_response_with_value(post_payload):
    responsePost = requests.post(POSTAPI_PROD,headers = POSTAPI_HEADERS,data=post_payload)
    print(responsePost)

#replaces the intended data for each value from payload data    
def replace_data_with_value(payload_data):
    post_payload = "replace function here" //works fine
    print "replace success"
    post_response_with_value(post_payload)

#get the response for each value.Invokes replace method 
def get_resposne_with_value(value):
    #input_url="URL/%s" % value
    response = requests.request("GET",input_url)
    print(response.status_code)
    json_response=json.loads(response.text)
    payload=json.dumps(json_response['payload'])
    replace_data_with_value(payload)

#reads values from input file.Invokes for 'GET' responses for each value    
def read_input_file_with_value():
    with open('file.txt', 'r') as data:
        for value in data:
            get_resposne_with_value(value)
    print "read file is success"       

read_input_file_with_value()
尝试删除\r\n

for value in data:
    clean_value = value.rstrip()
    get_resposne_with_value(clean_value)