the source code is as follows:
-sharp _*_ coding:utf-8 _*_
import os
import configparser
import codecs
-sharp
Path = os.path.join(os.getcwd(), os.listdir()[0])
print(Path)
def get_url(name):
config = configparser.ConfigParser()
config.read(Path)
url = config.get("HTTP", name)
return url
the configuration file is as follows:
[HTTP]
baseurl = https://mo.1394x.com
port = 8000
versoin = 3000
the call file is as follows:
import unittest
import requests
import sys
sys.path.append("..")
from config import readconfigfile as config
class TestGetAwardData(unittest.TestCase):
def setUp(self):
-sharp
self.host = config.get_url("baseurl")
-sharp APP
self.base_url = self.host + "/ssc/GetAwardData?version=3000"
print(self.base_url)
def test_status_code(self):
"""200"""
st_code = requests.get(self.base_url).status_code
st_json = requests.get(self.base_url).json()
self.assertEqual(st_code, 200)
if st_code != 200:
print("")
self.assertEqual(st_json["state"], 200)
self.assertEqual(st_json["items"]["state"], True)
self.assertEqual(st_json["error"], None)
print(len(st_json))
self.assertNotEqual(len(st_json), 0)
def tearDown(self):
pass
if __name__ == "__main__":
unittest.main()
< H2 > when the above code calls, prompt < / H2 >
Traceback (most recent call last):
File "E:/python_script/AutoTest/Api/Cqssc_api/case/test_01.py", line 12, in setUp
self.host = config.get_url("baseurl")
File "..\config\readconfigfile.py", line 25, in get_url
config.read(Path)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\configparser.py", line 697, in read
self._read(fp, filename)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\configparser.py", line 1015, in _read
for lineno, line in enumerate(fp, start=1):
UnicodeDecodeError: "gbk" codec can"t decode byte 0x80 in position 482: illegal multibyte sequence
Baidu has been unable to find a solution for a long time. Please give me some advice. 1