MemoryError: Cannot allocate write+execute memory for ffi.callback() requests报错

本机环境:Mac OS 11.2 python3.8

在requests的时候存在问题。
r = requests.get(url, headers=headers, timeout =10)
报的错误是这样的:
MemoryError: Cannot allocate write+execute memory for ffi.callback(). You might be running on a system that prevents this. For more information, see https://cffi.readthedocs.io/en/latest/using.html#callbacks
并且伴随着一堆ssl认证失败。

问题诊断:和ssl相关的某个库没有写和执行权限,经过资料查询初步确定为pyopenssl,openssl是有写和执行权限的,而pyopenssl则没有。我是因为下载了Scrapy,多了个这玩意。
解决办法:
看看自己有没有pyopenssl这个库,如果有则删除之:
执行:

pip3 uninstall pyopenssl

参考:

pyOpenSSL is not compatible with systems that prevent writeable and executable memory pages. You either have to disable the security feature, use another TLS library like the builtin ssl module, or redesign+rewrite pyOpenSSL’s callback system.

it’s a problem in pyOpenSSL. OpenSSL is fine.
I see how my comment can be understand the wrong way. I was referring to another Python TLS library such as ssl module from Python’s standard library. OpenSSL does not require executable+writable memory. The problem only effects pyOpenSSL.
It’s an implementation artifact of pyOpenSSL’s glue code that wraps OpenSSL’s C-API and makes it available for Python. pyOpenSSL uses CFFI, which is a Python interface to libffi. libffi (library for foreign function interface) uses dynamic code creation for dynamic callbacks. Every time the code passes a Python method to OpenSSL, it has to wrap the Python method into machine code, so it looks like a C function to the C-API of OpenSSL. It writes dynamic code to an executable memory page. CFFI calls this old style callbacks.
There are ways to work around the problem, but it’s complicated and lots of work. Nobody has contributed a solution yet.

具体可参考:https://github.com/pyca/pyopenssl/issues/873

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值