简体   繁体   English

Python-Sikuli-ConfigParser.NoSectionError

[英]Python - Sikuli - ConfigParser.NoSectionError

This is my code: 这是我的代码:

import ConfigParser
configuration = ConfigParser.ConfigParser()
configuration.read('timesheetconfig.ini')
username = configuration.get('internal','username')
password = configuration.get('internal','password')
url  = configuration.get('internal','url')
browser = configuration.get('internal','browser') 

I've also tried replacing: configuration.read('C:\\SikuliConfig\\timesheetconfig.ini') 我也尝试过替换:configuration.read('C:\\ SikuliConfig \\ timesheetconfig.ini')

This is the timesheetconfig.ini 这是timesheetconfig.ini

[internal]
username = username
password = password
url = https://www.sometimesheeturl/login.html
browser = chrome

Do you know why I'm getting??? 你知道我为什么得到吗???

[error] script [ ScriptName ] stopped with error in line 4
[error] ConfigParser.NoSectionError ( No section: 'internal' )

For some reason the configuration.read cannot open the file in the same folder. 由于某些原因,configuration.read无法在同一文件夹中打开文件。 I tested the same code in Python with Cygwin and it works fine, so it is related to Sikuli. 我使用Cygwin在Python中测试了相同的代码,并且效果很好,因此与Sikuli有关。

I solved this issue by adding after import ConfigParser: 我通过在导入ConfigParser之后添加来解决此问题:

import ConfigParser
# get the directory containing your running .sikuli
myPath = os.path.dirname(getBundlePath())
if not myPath in sys.path: sys.path.append(myPath)

Then 然后

config.read('%s\config.ini' % myPath)

Source search in Sikuli docs for "Another example: Importing from the same directory" 在Sikuli docs中对“另一个示例:从同一目录导入”进行源搜索

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM