我尝试使用套接字来发送JSON数据发送JSON数据,但得到这个错误如何使用SSL
b'HTTP/0.9 413请求实体过大\ r \ n服务器: inets/5.10 .2 \ r \ n日期:2016年8月5日星期五18:19:38 GMT \ r \ n内容类型: text/html \ r \ n内容长度:202 \ r \ n \ r \ n'
我的代码:
def single_contract(amount, service_key):
current_date = datetime.now()
fee = 0
if amount > 10000.0:
fee = amount * 0.01
if os.path.exists('./Files/Point.txt'):
with open('./Files/Point.txt') as opened_file:
point_id = opened_file.read()
json_data = dict()
json_data["single_contract"] = dict()
json_data["single_contract"]["point_id"] = point_id.strip()
json_data["single_contract"]["datetime"] = datetime.strftime(current_date, '%Y-%m-%d %H:%M:%S')
json_data["single_contract"]["external_transaction_id"] = randint(999999999, 9999999999)
json_data["single_contract"]["service_id"] = 1001351861392575516
json_data["single_contract"]["amount"] = amount
json_data["single_contract"]["service_key"] = service_key
json_data["single_contract"]["fee"] = round(fee, 2)
json_data["single_contract"]["params"] = None
with open('./Files/sending_file.json', mode='w', encoding='utf-8') as json_file:
json.dump(json_data, json_file)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sslcontext = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)
sslcontext.load_verify_locations('./Files/ca-cert.pem')
sslcontext.load_cert_chain(certfile='./Files/com-cert.pem',
keyfile='./Files/com-key.pem')
host = '***.***.***.***'
port = ****
ssl_socket = sslcontext.wrap_socket(sock, server_hostname=host)
ssl_socket.connect((host, port))
with open('./Files/sending_file.json', mode='rb') as f:
ssl_socket.sendfile(f)
with open('./Files/answer.txt', mode='w', encoding='utf-8') as reply:
reply.write(str(ssl_socket.recv()))
ssl_socket.close()
print('End of connection')
else:
print('No such file or directory.')
什么是I D在这里错了吗?谢谢
代码中的缩进看起来搞砸了。 – jmdeamer