我把我做网络爬虫和javascript代码的python放在一起。
但是,出现错误:"HTTPSConnectionPool(host='www.twreporter.org', port=443): Max retries exceeded with url: /topics?page=13 (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))"
我试图在我的python代码中import ssl
,但是一旦完成,它就会:
undefined:1
Traceback (most recent call last):
^
SyntaxError: Unexpected token T in JSON at position 0
甚至代码也只有:
import json
import ssl
print(json.dumps("1234"))
我该如何解决?
这是我的JavaScript代码的一部分:
let { PythonShell } = require('python-shell')
let options = {
mode: 'json',
pythonOptions: ['-u'],
scriptPath: './python',
};
PythonShell.run('pythontest.py', options, function (err, results, res) {
if (err) console.log(err);
// results is an array consisting of messages collected during execution
console.log(results);
}
JavaScript中的compelet错误:
undefined:1
Traceback (most recent call last):
^
SyntaxError: Unexpected token T in JSON at position 0
at JSON.parse (<anonymous>)
at PythonShell.asJson (D:\【code】\database\Reporter\node_modules\python-shell\index.js:358:21)
at D:\【code】\database\Reporter\node_modules\python-shell\index.js:310:42
at Array.forEach (<anonymous>)
at PythonShell.recieveInternal (D:\【code】\database\Reporter\node_modules\python-shell\index.js:306:15)
at PythonShell.receiveStderr (D:\【code】\database\Reporter\node_modules\python-shell\index.js:290:21)
at Socket.<anonymous> (D:\【code】\database\Reporter\node_modules\python-shell\index.js:108:18)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
操作系统:Windows 10
python:python 3.7
编译器:Visual Studio代码
顺便说一句,python代码可以在我的计算机或google colab上单独运行。
最佳答案
紫ster
谢谢你的问题!我已经尝试了2天,以找到针对SSLError(“由于SSL模块不可用,无法连接至HTTPS URL。”)问题引起的解决方案。
我的设置与您的设置相同(Win10,py3.7-均为全新安装)。
我正在使用的特定程序与您的不同(DIY财务数据抓取脚本/ PyCharm / Anaconda3)。在过去的一年或更长的时间内,这一直很好,直到我被迫对所有内容进行全新安装。
我的预感(基于其他响应)是它与system32目录中的libcrypto.dll文件有关。也许是“劫持它” ????
希望有人以我能理解的方式回答您的问题(我今年76岁,从200年前开始使用Fortran,运行python脚本已有大约15年的时间,但是我通常只是找到一些适合我需要的东西,不要试图弄乱它)
再次感谢您的提问!