1. When sending a request using requests, the response data is turned into JSON hint, there is no JSON to decode
Workaround:
This is due to the sending of the requested data, there is an error, the response error such as 404 400, so can not find the JSON to decode
Examples are as follows:
" " {' userName ': ' 13718651996 ', ' passwd ': ' yhlxxxx870120 ', ' validatecode ': ' abc ', ' rememberme ': ' True ' }"'https://secure.elong.com/passport/ajax/elongLogin' = Session (). Post (url,data=postdata)print(Response.json ())
In fact, it is clear from the diagram that the problem is apparent because postdata is a string type, not a dict dictionary
such as code if the following error is reported:
Workaround, the eval () function converts the string into a dictionary, as shown below
" " {' userName ': ' 13718651996 ', ' passwd ': ' yhlxxxx870120 ', ' validatecode ': ' abc ', ' rememberme ': ' True ' }"'https://secure.elong.com/passport/ajax/elongLogin' = Session (). Post (url,data=eval (postdata))print(Request.json ())
Some might say, aren't you superfluous? The postdata is directly defined as a dictionary; you're right, you can do that.
PostData = {'UserName':'13718651996', 'passwd':'yhlxxxx870120', 'Validatecode':'ABC', 'RememberMe':'true'}url='Https://secure.elong.com/passport/ajax/elongLogin'Request= Session (). Post (url,data=postdata)Print(Request.json ())
But if the following string of data, stored in the database, or Excel, read out the default is the string, if you read it directly using the error will appear in this article,
So what's wrong with this is to know that this is a small detail; debug output, the discovery output is the same as the following,
There is nothing wrong with this is the dictionary {' xxxx ': ' xxx ' ...}, but it is a string. Easy to ignore, so use the eval (postdata) function to turn into a dictionary
{'UserName':'13718651996', 'passwd':'yhlxxxx870120', 'Validatecode':'ABC', 'RememberMe':'true'}
Correct code:
PostData = "' {'UserName':'13718651996', 'passwd':'yhlxxxx870120', 'Validatecode':'ABC', 'RememberMe':'true'} ' URL='Https://secure.elong.com/passport/ajax/elongLogin'Request= Session (). Post (url,data= eval (postdata))Print(Request.json ())
------------------------------I'm a gorgeous divider line----------------------------------
2.
Python in use error (continuous update ...)