从 ini 文件中解析错误的值,我如何从用户名 = 字段而不是值中解析用户名?
1) Ini 文件存储有预定义的预设,我需要在 python 中读取
$ cat /var/tmp/file.ini
banner=QUESTIONS sentence
network=lan
programming=pytohn
url=http\://pbx/register?username=E300B1&password=1234&option=localip&localip=
username=E300B1
password=1234
server=pbx
2)代码:我尝试的用户名/密码字段似乎错误
import re,os, time, socket, datetime, threading, subprocess, logging, gtk, gobject
logging.basicConfig(filename='/var/tmp/log.log',level=logging.DEBUG)
def readini(findme):
f = open('/var/tmp/file.ini', "r")
for line in f:
if line:
if findme in line:
r= line.split("=")
return r[1].replace("\\n", "").rstrip()
host = readini("server")
username = preadini("username")
password = readini("password")
command = """curl 'http://%s/a/b?username=%s&password=%s&language=EN'""" % (host, username, password)
logging.debug( command )
os.system( command )
3)输出(错误):
DEBUG:root:curl 'http://192.168.1.10/a/b?username=http\://pbx/register?username&password=http\://pbx/register?username&language=EN'
4)预期输出为:
DEBUG:root:curl 'http://192.168.1.10/a/b?username=E300B1&password=1234&language=EN'