transcrypt 连接池错误
transcrypt connectionpool error
我对编码和网络开发还很陌生。我是一名系统工程师,希望进入 Web 开发方面。我学习了一些 python 教程并拼凑了一个(可能非常)粗糙的 python 应用程序。我现在想将该应用程序放在我创建的网站上,这样我就可以让办公室里的其他人也可以使用该实用程序。
为此,我安装了 transcrypt,目的是将 python 代码转换为 javascript。当 运行ning transcrypt 我得到以下输出:
Error while compiling (offending file last):
File 'c:/Scripting/Transcrypt/Meraki.py', line 1, at import of:
File 'c:/users/dab404/appdata/local/programs/python/python36/lib/site-packages/requests/init.py', line 43, at import of:
File 'c:/users/dab404/appdata/local/programs/python/python36/lib/site-packages/urllib3/init.py', line 8, namely:
Attempt to import module: connectionpool
Can't find any of:
c:/Scripting/Transcrypt/connectionpool.py
c:/Scripting/Transcrypt/javascript/connectionpool.mod.js
错误继续列出它需要 运行 的大约 10 个其他文件。我不确定如何解决这个问题,如果有人能给我任何帮助,我将不胜感激。
这是我的代码:
import requests
import json
from meraki import meraki
base_url = "https://dashboard.meraki.com/api/v0/"
def List_Orgs(apikey): #A FUNCTION FOR LISTING ORGANIZATION ADMINS
myOrgs = meraki.myorgaccess(apikey)
for orgs in myOrgs:
print(orgs)
def List_Admins(URL_admin, headers):
x = requests.get(URL_admin, headers = headers)
myAdmins = x.json()
for admins in myAdmins:
print(admins)
def Add_Admin(URL, admin_data, headers): #FUNCTION FOR ADDING NEW ADMIN
TO AN ORGANIZATION
r = requests.request("POST", URL, data = admin_data, headers = headers)
print(r.status_code)
if (r.status_code) == 201:
print()
print()
print("Administrator successfully added!")
print()
else:
print()
print("Administrator was NOT successfully added. Please try again!")
print()
def Del_Admin(URL_del, headers): #FUNCTION FOR DELETING AN ADMIN FROM AN
ORGANIZATION
r = requests.request("DELETE", URL_del, headers = headers)
print(r.status_code)
if (r.status_code) == 204:
print()
print()
print("Administrator successfully deleted!")
print()
else:
print()
print("Administrator was NOT successfully deleted. Please try again!")
print()
apikey = input("What is your Meraki API key? ")
print()
print("******************************************")
print()
print("Here is a list of your Organizations. You will need the ID to answer
the next set of questions.")
print()
print()
List_Orgs(apikey)
print()
print()
headers = {
'X-Cisco-Meraki-API-Key': apikey,
'Content-Type': "application/json"
}
add_or_del = input("Would you like to add or delete an admin? ")
if add_or_del == ("add" or "Add" or "ADD"):
orgid = input("Which Organization would you like to add an admin to? ")
admin_name = input("What is the new Admin's First and Last name? ")
admin_email = input("What is " + admin_name + "'s email address? ")
admin_access = input("What level of access would you like " + admin_name +
" to have? (full or read-only) ")
admin_data = '{\n\t\"name\":\"' + admin_name + '\",\n\t\"email\":\"' +
admin_email + '\",\n\t\"orgAccess\":\"' + admin_access + '\"}'
URL = (base_url + 'organizations/' + orgid + '/admins')
Add_Admin(URL, admin_data, headers)
elif add_or_del == ("delete" or "Delete" or "DELETE"):
orgid = input("Which Organization would you like to delete an admin from?
")
URL_admin = (base_url + 'organizations/' + orgid + '/admins/')
print()
print("Here is a list of Admins in this Organization. You will need to
admin ID to answer the next question.")
print()
print()
List_Admins(URL_admin, headers)
print()
print()
adminid = input ("What is the admin's Meraki portal ID? ")
URL_del = (base_url + 'organizations/' + orgid + '/admins/' + adminid)
Del_Admin(URL_del, headers)
else:
print("Please type add or delete and try again.")'
谢谢!
大卫
问题在于导入:
import requests
import json
from meraki import meraki
像 requests
这样的模块是 Transcrypt 不支持的标准 Python 模块,因为它使用用 C 编写的代码,在浏览器中 运行 .
对于 json
有一个 JavaScript 对应物可以直接从 Transcrypt 使用而不会出现问题。
模块meraki
我不知道,所以无法判断。
虽然 Transcrypt 发行版中提供了越来越多的标准模块,但通常它会使用 JavaScript 模块,因为这些模块专门针对在浏览器中有意义的功能。
例如本地文件访问通常在浏览器中是被禁止的,所以任何使用它的模块都不能做到这一点 'thing'.
另请参阅:
http://www.transcrypt.org/docs/html/what_why.html#the-ecosystem-different-batteries
所以在 Transcrypt 中你在 Python 中编程,但是你使用的库主要是 JavaScript。例外是非常常见的库,例如 math、cmath、random(部分)、time、datetime、itertools、re 等
要了解如何使用 Transcrypt 中的 JavaScript 库,请查看:
http://www.transcrypt.org/examples
还有:
http://www.transcrypt.org/docs/html/integration_javascript.html#mixed-examples
[编辑]
我又仔细查看了您的应用程序,我注意到它是一个典型的控制台应用程序,使用 input
和 print
之类的东西。虽然 Transcrypt 以有限的方式支持这些,请参阅
一般的 Web 应用程序工作方式有所不同。
通常它们是事件驱动的,这意味着许多 GUI 元素拼凑在一起,有时在 HTML 中,有时在脚本中。然后这些 GUI 元素触发事件,进而触发某些代码片段(事件处理程序)成为 运行.
所以下一步可能是研究这种工作方式。 HTML/DOM 和以这种方式合作的脚本在 Transcrypt 中的一个很好的简单示例是:
http://www.transcrypt.org/docs/html/installation_use.html#your-first-transcrypt-program
在许多情况下,Web 应用程序还与 Web 服务器进行交互,因此部分处理是在服务器上完成的。
你可以,例如为此使用 Bottle 或 Django,如在以下位置演示的那样:
https://github.com/Michael-F-Ellis/NearlyPurePythonWebAppDemo
我对编码和网络开发还很陌生。我是一名系统工程师,希望进入 Web 开发方面。我学习了一些 python 教程并拼凑了一个(可能非常)粗糙的 python 应用程序。我现在想将该应用程序放在我创建的网站上,这样我就可以让办公室里的其他人也可以使用该实用程序。
为此,我安装了 transcrypt,目的是将 python 代码转换为 javascript。当 运行ning transcrypt 我得到以下输出:
Error while compiling (offending file last): File 'c:/Scripting/Transcrypt/Meraki.py', line 1, at import of: File 'c:/users/dab404/appdata/local/programs/python/python36/lib/site-packages/requests/init.py', line 43, at import of: File 'c:/users/dab404/appdata/local/programs/python/python36/lib/site-packages/urllib3/init.py', line 8, namely: Attempt to import module: connectionpool Can't find any of: c:/Scripting/Transcrypt/connectionpool.py c:/Scripting/Transcrypt/javascript/connectionpool.mod.js
错误继续列出它需要 运行 的大约 10 个其他文件。我不确定如何解决这个问题,如果有人能给我任何帮助,我将不胜感激。
这是我的代码:
import requests
import json
from meraki import meraki
base_url = "https://dashboard.meraki.com/api/v0/"
def List_Orgs(apikey): #A FUNCTION FOR LISTING ORGANIZATION ADMINS
myOrgs = meraki.myorgaccess(apikey)
for orgs in myOrgs:
print(orgs)
def List_Admins(URL_admin, headers):
x = requests.get(URL_admin, headers = headers)
myAdmins = x.json()
for admins in myAdmins:
print(admins)
def Add_Admin(URL, admin_data, headers): #FUNCTION FOR ADDING NEW ADMIN
TO AN ORGANIZATION
r = requests.request("POST", URL, data = admin_data, headers = headers)
print(r.status_code)
if (r.status_code) == 201:
print()
print()
print("Administrator successfully added!")
print()
else:
print()
print("Administrator was NOT successfully added. Please try again!")
print()
def Del_Admin(URL_del, headers): #FUNCTION FOR DELETING AN ADMIN FROM AN
ORGANIZATION
r = requests.request("DELETE", URL_del, headers = headers)
print(r.status_code)
if (r.status_code) == 204:
print()
print()
print("Administrator successfully deleted!")
print()
else:
print()
print("Administrator was NOT successfully deleted. Please try again!")
print()
apikey = input("What is your Meraki API key? ")
print()
print("******************************************")
print()
print("Here is a list of your Organizations. You will need the ID to answer
the next set of questions.")
print()
print()
List_Orgs(apikey)
print()
print()
headers = {
'X-Cisco-Meraki-API-Key': apikey,
'Content-Type': "application/json"
}
add_or_del = input("Would you like to add or delete an admin? ")
if add_or_del == ("add" or "Add" or "ADD"):
orgid = input("Which Organization would you like to add an admin to? ")
admin_name = input("What is the new Admin's First and Last name? ")
admin_email = input("What is " + admin_name + "'s email address? ")
admin_access = input("What level of access would you like " + admin_name +
" to have? (full or read-only) ")
admin_data = '{\n\t\"name\":\"' + admin_name + '\",\n\t\"email\":\"' +
admin_email + '\",\n\t\"orgAccess\":\"' + admin_access + '\"}'
URL = (base_url + 'organizations/' + orgid + '/admins')
Add_Admin(URL, admin_data, headers)
elif add_or_del == ("delete" or "Delete" or "DELETE"):
orgid = input("Which Organization would you like to delete an admin from?
")
URL_admin = (base_url + 'organizations/' + orgid + '/admins/')
print()
print("Here is a list of Admins in this Organization. You will need to
admin ID to answer the next question.")
print()
print()
List_Admins(URL_admin, headers)
print()
print()
adminid = input ("What is the admin's Meraki portal ID? ")
URL_del = (base_url + 'organizations/' + orgid + '/admins/' + adminid)
Del_Admin(URL_del, headers)
else:
print("Please type add or delete and try again.")'
谢谢! 大卫
问题在于导入:
import requests
import json
from meraki import meraki
像 requests
这样的模块是 Transcrypt 不支持的标准 Python 模块,因为它使用用 C 编写的代码,在浏览器中 运行 .
对于 json
有一个 JavaScript 对应物可以直接从 Transcrypt 使用而不会出现问题。
模块meraki
我不知道,所以无法判断。
虽然 Transcrypt 发行版中提供了越来越多的标准模块,但通常它会使用 JavaScript 模块,因为这些模块专门针对在浏览器中有意义的功能。
例如本地文件访问通常在浏览器中是被禁止的,所以任何使用它的模块都不能做到这一点 'thing'.
另请参阅:
http://www.transcrypt.org/docs/html/what_why.html#the-ecosystem-different-batteries
所以在 Transcrypt 中你在 Python 中编程,但是你使用的库主要是 JavaScript。例外是非常常见的库,例如 math、cmath、random(部分)、time、datetime、itertools、re 等
要了解如何使用 Transcrypt 中的 JavaScript 库,请查看:
http://www.transcrypt.org/examples
还有:
http://www.transcrypt.org/docs/html/integration_javascript.html#mixed-examples
[编辑]
我又仔细查看了您的应用程序,我注意到它是一个典型的控制台应用程序,使用 input
和 print
之类的东西。虽然 Transcrypt 以有限的方式支持这些,请参阅
一般的 Web 应用程序工作方式有所不同。
通常它们是事件驱动的,这意味着许多 GUI 元素拼凑在一起,有时在 HTML 中,有时在脚本中。然后这些 GUI 元素触发事件,进而触发某些代码片段(事件处理程序)成为 运行.
所以下一步可能是研究这种工作方式。 HTML/DOM 和以这种方式合作的脚本在 Transcrypt 中的一个很好的简单示例是:
http://www.transcrypt.org/docs/html/installation_use.html#your-first-transcrypt-program
在许多情况下,Web 应用程序还与 Web 服务器进行交互,因此部分处理是在服务器上完成的。
你可以,例如为此使用 Bottle 或 Django,如在以下位置演示的那样:
https://github.com/Michael-F-Ellis/NearlyPurePythonWebAppDemo