Python Forum
Correct py got error on another windows 7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Correct py got error on another windows 7
#1
So sorry that I can't describe accurately in the title because I don't really understand this issue.
I have a simple Py file which simply post some data to a website.It worked very well on my Windows 10 and windows 7, but got strange error on another windows 7. Part of the codes:

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

headers={
        "Host": "something.com",
        "Connection": "keep-alive",
        "Content-Length": "100",
        
}
   
def format(Cookie):
    cookies = {}
    for line in Cookie.split(";"):
            if line.find("=") != -1:  
                name, value = line.strip().split("=")
                cookies[name] = value
    return cookies

fp = open ("1.txt","r")
Cookie = fp.read()
fp.close()
CookieNew = format(Cookie)
DataNew = '{"vId":"000104","serviceId":"1002"}'

requests.post(url, data=DataNew, headers=headers, cookies=CookieNew)
The format(cookie) function changes the format to JSON I guess because the website only accept this format.(Googled)
The first error is
Error:
UnicodeEncodeError: 'latin-1' codec can't encode characters in position xx-xx: ordinal not in range(256)
Then I googled and changed the
fp = open ("1.txt","r")
to
fp = open ("1.txt","r",encoding = "utf-8-sig")
Now I got this error from website:
{"timestamp":"2020-04-23 16:47:15","status":500,"error":"Internal
Server Error","exception":"org.springframework.http.converter.HttpMessageNotRead
ableException","message":"Could not read document: Unexpected character ('i' (co
de 105)): was expecting comma to separate OBJECT entries\n at [Source: java.io.P
ushbackInputStream@6bc0aae7; line: 1, column: 105]; nested exception is com.fast
erxml.jackson.core.JsonParseException: Unexpected character ('i' (code 105)): wa
s expecting comma to separate OBJECT entries\n at [Source: java.io.PushbackInput
Stream@6bc0aae7; line: 1, column: 105]","path":"/dir/cou/submit"}
I'm confused that this is the same py file. What makes this error and how do I google this because it looks like java responses.

If I use encoding = "utf-8" instead of encoding = "utf-8-sig", the error is
Error:
UnicodeEncodeError: 'latin-1' codec can't encode character '\ufeff' in position xx: ordinal not in range(256)
The OS of windows 10 and the widnows 7 with py error are Asia version,the other windows7 without error is English version.

The content of 1.txt here,it's a cookie file.

Output:
Hm_lvt_4a693f348daf8481dd541c844122c053=1585791910; JSESSIONID=D524881BB65001A53B445AA4EDC14FC7; Hm_lpvt_4a693f348daf8481dd541c844122c053=1587654145; Hm_lvt_bc864c0a0574a7cabe6b36d53206fb69=1583560881;
Thanks for help and sorry for the chaotic description. Cry
Reply


Messages In This Thread
Correct py got error on another windows 7 - by meetinnet - Apr-24-2020, 03:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  "SSL: CERTIFICATE_VERIFY_FAILED” error on Python 3.9.6 (Windows 10) rcmv 4 3,734 May-10-2022, 01:18 PM
Last Post: rcmv
  how can I correct the Bad Request error on my curl request tomtom 8 5,140 Oct-03-2021, 06:32 AM
Last Post: tomtom
  error while installing any library using pip in windows AkashKansal 1 4,442 Sep-24-2020, 07:51 AM
Last Post: buran
  attribute error instead of correct output MaartenRo 2 2,228 Aug-28-2020, 10:22 AM
Last Post: Larz60+
  Python 3.7, Windows 7, Syntax Error hughdent 1 2,309 Mar-23-2020, 10:09 AM
Last Post: buran
  Getting the error like function not defined .. suggest correct code raghava 1 2,093 Feb-04-2020, 11:20 PM
Last Post: micseydel
  Error in compiling cython extension on Python 3.6.4 on Windows 8 goldenmean 3 5,823 Jun-05-2019, 09:37 PM
Last Post: Larz60+
  Windows 10 Task Scheduler Error mypython 1 2,519 Aug-11-2018, 11:01 PM
Last Post: ichabod801
  Windows cannot find "wish.exe" - error while trying to run PAGE Nwb 0 7,552 Jun-11-2018, 12:08 PM
Last Post: Nwb
  Error when creating child process on Windows 10 Charles 0 3,257 May-30-2018, 01:24 PM
Last Post: Charles

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020