Home > other >  The same py report file in individual computers very strange fault.
The same py report file in individual computers very strange fault.

Time:09-20

Very simple script, function is simple, in a Win10 and a Windows 7 normal operation, in another new Windows 7 is an error, baidu for a long time also don't know why,

 #! The/usr/bin/env python 
# - * - coding: utf-8 - * -
The import requests
Url='https://someweb.com/submit'

Headers={
"The Host" : "something.com",
"Connection" : "keep - the alive,"
"The Content - Length", "100",

}

Def format (cookies) :
Cookies={}
For the line in a Cookie. Split (";" ) :
If the line. The find ("=")!=1:
Name, value=(https://bbs.csdn.net/topics/line.strip). The split ("=")
Cookies, [name]=value
Return the cookies

Fp=open (" 1. TXT ", "r")
Cookie=fp. Read ()
Fp. Close ()
CookieNew=format (cookies)
DataNew='{" vId ":" 000104 ", "serviceId" : "1002"}'

Requests. Post (url, data=https://bbs.csdn.net/topics/DataNew, headers=headers, cookies=CookieNew)


The format function is to convert the cookies to JSON,
Direct copy past run at this wrong:

 UnicodeEncodeError: 'latin-1' codec can 't encode characters in the position of xx, xx: 
The ordinal not in range (256)


Baidu, the open files with encoding to fp=open (" 1. TXT ", "r", encoding="utf-8 - sig"), an error is:

 {" timestamp ":" the 2020-04-23 16:47:15 ", "status" : 500, "error" : "Internal 
Server Error ", "exception" is: "org. Springframework. HTTP. Converter. HttpMessageNotRead
AbleException ", "message" : "Could not read the document: Unexpected character (' I '(co
DE 105) : the was expecting comma to separate the OBJECT entries \ n at [Source: Java. IO. P
UshbackInputStream @ 6 bc0aae7; Line: 1, the column: 105]; Nested exception is com. Fast
Erxml. Jackson. Core. JsonParseException: Unexpected character (' I '(105) code) : wa
S expecting comma to separate the OBJECT entries \ n at [Source: Java. IO. PushbackInput
The Stream @ 6 bc0aae7; Line: 1, the column: 105] ", "path" : "/dir/cou/submit"}


This is the wrong site to return to, but don't understand why, on requests. Post that,
The problem is the py script run on the two win10 and Windows 7 no problem ah, what all don't change, and what is new this Windows 7 environment,

Cookie content is:

 Hm_lvt_4a693f348daf8481dd541c844122c053=1585791910; JSESSIONID=D524881BB65001A53B445AA4EDC14FC7; Hm_lpvt_4a693f348daf8481dd541c844122c053=1587654145; Hm_lvt_bc864c0a0574a7cabe6b36d53206fb69=1583560881; 



Do not know how to start feeling, feel is coding issues, but don't know how to change again,

CodePudding user response:

UnicodeEncodeError solved, the coding problem, change to utf-8 is not an error, now left site to the mistake, can't check what's the matter, baidu has a JSON problem, but the two normal is also in this file,
  • Related