【.NET调用Python脚本】C#调用python requests类库报错 'module' object has no attribute '_getframe' - IronPython 2.7
2016-12-21 16:55
766 查看
最近在开发微信公众号,有一个自定义消息回复的需求
不同的提问可能需要查询不同的接口数据,这个时候想把每个接口调用做成一个Python脚本插件,在程序运行过程中动态去请求不同接口,扩展性强。
这个时候找到了【IronPython】,在C#程序里执行py脚本。
但是调试过程中出现了一个错误
搜了一下错误信息,已经有前人遇到过这个问题,但是并没有给出最终解决方案 http://www.itnose.net/detail/6519438.html
郁闷了,估计是一个三方库【import requests】和系统库冲突
因为在正常使用Python自有类库的时候没有问题,只要引用了三方类库,立马报错。
翻官方文档发现
大致意思是在NET里没有实现这个 _getframe 方法,而requests用到了,自然报错。
妈蛋的,此路不通,只能转换思路,想其它方法实现需求了。requests 坑爹啊
第二天,今天FQgoogle一搜,妈蛋的,直接第一个就是解决方案 http://stackoverflow.com/questions/6997832/ironpython-sys-getframe-not-found
然并卵,按照上面的做了,又出现了新问题,无穷无尽。。。
pip install urllib3 解决,又报错如下
麻痹,没完没了的报错。
不搞了,艹!
比如用户:麻烦帮我查询一下北京的天气? 系统回复:北京天气,晴,8-13℃。。。 这时候需要根据关键字【北京】【天气】,分词匹配需要执行的操作,然后去调用天气接口,请求天气数据。
不同的提问可能需要查询不同的接口数据,这个时候想把每个接口调用做成一个Python脚本插件,在程序运行过程中动态去请求不同接口,扩展性强。
def get_baidu_html(): import urllib2 import sys url = 'http://1212.ip138.com/ic.asp' html_content = urllib2.urlopen(url).read() return html_content
这个时候找到了【IronPython】,在C#程序里执行py脚本。
但是调试过程中出现了一个错误
“System.MissingMemberException”类型的未经处理的异常在 Microsoft.Dynamic.dll 中发生 其他信息: 'module' object has no attribute '_getframe'
搜了一下错误信息,已经有前人遇到过这个问题,但是并没有给出最终解决方案 http://www.itnose.net/detail/6519438.html
[.NET&ironpython]C#调用python文件时出现'module' object has no attribute '_getframe'
郁闷了,估计是一个三方库【import requests】和系统库冲突
因为在正常使用Python自有类库的时候没有问题,只要引用了三方类库,立马报错。
翻官方文档发现
A new implementation-dependent function, sys._getframe([depth])(), has been added to return a given frame object from the current call stack. sys._getframe() returns the frame at the top of the call stack; if the optional integer argument depth is supplied, the function returns the frame that is depth calls below the top of the stack. For example, sys._getframe(1) returns the caller’s frame object. This function is only present in CPython, not in Jython or the .NET implementation. Use it for debugging, and resist the temptation to put it into production code.
大致意思是在NET里没有实现这个 _getframe 方法,而requests用到了,自然报错。
妈蛋的,此路不通,只能转换思路,想其它方法实现需求了。requests 坑爹啊
第二天,今天FQgoogle一搜,妈蛋的,直接第一个就是解决方案 http://stackoverflow.com/questions/6997832/ironpython-sys-getframe-not-found
var options = new Dictionary<string, object>(); options["Frames"] = true; options["FullFrames"] = true; ScriptEngine engine = Python.CreateEngine(options);
然并卵,按照上面的做了,又出现了新问题,无穷无尽。。。
“IronPython.Runtime.Exceptions.ImportException”类型的未经处理的异常在 Microsoft.Dynamic.dll 中发生 其他信息: No module named urllib3
pip install urllib3 解决,又报错如下
“IronPython.Runtime.Exceptions.ImportException”类型的未经处理的异常在 Microsoft.Dynamic.dll 中发生 其他信息: No module named http_client
麻痹,没完没了的报错。
不搞了,艹!
相关文章推荐
- python 错误AttributeError: 'module' object has no attribute 'AF_INET'
- python调用对象属性出错:AttributeError: 'function' object has no attribute '_name_'
- python问题:AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
- 【转载】C#调用python文件时出现'module' object has no attribute '_getframe'
- Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'
- Python基础学习-'module' object has no attribute 'urlopen'解决方法
- python 中出现的AttributeError: 'module' object has no attribute '_handlerList'
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
- C#调用Python脚本的简单示例,IronPython(转载)
- IronPython脚本调用C#dll示例
- AttributeError: 'module' object has no attribute 'AF_INET' 错误的原因
- httplib:AttributeError: 'module' object has no attribute 'HTTPConnection'
- [DONE]pomelo npm-install 出现 AttributeError: 'module' object has no attribute 'script_main'
- Python python __def__ Exception AttributeError: "'NoneType' object has no attribute
- python2.7嵌入c++的故事之一:c++调用脚本出现Import error: no module named错误
- C# 调用批python 脚本
- python import 错误 TypeError: 'module' object is not callable
- python错误TypeError: 'module' object is not callable 的解决方法
- python httplib2 - AttributeError: 'NoneType' object has no attribute 'makefile'
- 提示AttributeError: 'module' object has no attribute 'HTTPSHandler'解决方法