0

Specs: Python version 3.7.3 (64-bit) IDE Microsoft Code (latest edition as of 4/23)

Background I am having issues with executing my code with Configparser only on Microsoft code. I installed other IDE's pycharm etc and I do not have any issues. I prefer Microsoft Code interface / debugging so I would prefer to keep using it. I even went an extra step and installed MS-Code on another server and tried to exec my code with the exact same issue. On a side note if you execute the code in debug mode in ms-code it works without a key error.

This issue is really confusing to me and any help would be appreciated

Current structure of Configparser in code

config = configparser.ConfigParser()
config.read('api_config.ini')

#Reads in each of the api URLs to use from the config file
line_item_reporting = config['apis']['line_item_reporting']
line_item_meta = config['apis']['line_item_meta']
package_reporting = config['apis']['package_reporting']
package_meta = config['apis']['package_meta']
io_meta = config['apis']['io_meta']
io_reporting = config['apis']['io_reporting']

Error code line_item_reporting = config['apis']['line_item_reporting'] File "C:\ProgramData\Anaconda3\lib\configparser.py", line 958, in getitem raise KeyError(key) KeyError: 'apis'

api_config.ini

[general]
meta_pull=50
num_loops=10
index_start=0
index_end=20
password=#######
lookback_window=3

[apis]
io_reporting = https://some_url
line_item_reporting = https://some_url
line_item_meta = https://some_url
package_reporting = https://some_url
package_meta = https://some_url
io_meta = https://some_url
2
  • I found that if i add the full pathway in MS-Code for the api_config file it works. However I am still confused why all of the other IDE's and even MS-Code begugger does not require the full path. I assume the issue is based on the file location vs the python installation but it should be the same as I only have 1 python installation installed 1 version.
    – Ryan Bowns
    Apr 23, 2020 at 0:39
  • I have the solution just not the why which to me is the most important. Solution is taken from Jean-François Fabre conf_file = os.path.join(os.path.dirname(os.path.dirname(file)),'api_config.ini') The above code adds a direct path between tools.py and the file location.
    – Ryan Bowns
    Apr 24, 2020 at 0:09

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.