目的:
从config.ini读取网址,使用request进行访问,post数据
遇到问题:
requests.exceptions.InvalidSchema: No connection adapters were found for ''https://httpbin.org/post''
原因:config解析的时候默认以字符串的形式读取内容,即会在所读取的内容外面包两个单引号( ' )
错误:
[http]
URL_GET_OPERATOR = 'https://api.github.com/events'
URL_POST_DATA = 'https://httpbin.org/post'
正确:
[http]
URL_GET_OPERATOR = https://api.github.com/events
URL_POST_DATA = https://httpbin.org/post
解决方案:
1.在读取部分添加一层eval()
url = eval(config.get("http", "URL_POST_DATA"))
2.在写配置文件的时候,就不要加单引号了,习惯了。。。。。。。。