Tag: python

不同的本地主机端口导致Access-Control-Allow-Origin失败

我想在localhost:3000上托pipe一个Docker JavaScript应用程序(RocketChat),并引用正在侦听localhost:5000的python脚本。 运行脚本我得到以下回应: [错误] Access-Control-Allow-Origin不允许源localhost:3000。 [错误]加载资源失败:Access-Control-Allow-Origin不允许使用Origin localhost:3000。 (响应,第0行)[错误]由于访问控制检查,XMLHttpRequest无法加载localhost:5000 / response。 正在执行的请求如下所示: var data = []; var client = new XMLHttpRequest(); if(input.value !== "" && input.value){ data["Type A"] = input.value; } else { data["Type B"] = "not valid"; } client.open("POST", "http://localhost:5000/response", true); client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); client.withCredentials = false; client.send(data); 如何编辑本地主机以启用Access-Control-Allow-Origin? 所有我能find的答案都提到编辑Node.js,我没有。

脚本在构build失败,但从Docker容器工作

我正在尝试通过Docker运行unit testing,以便对文件和目录创build,移动和重命名作出反应。 这是脚本: #/bin/bash # Launch Redis server redis-server –daemonize yes # Start directory_observer python /test/directory_observer/src/directory_observer.py –config=/test/directory_observer/tests/directory_observer.ini & # Execute test script (operations in the folders) bash /test/directory_observer/tests/Dockerfile_testing/directory_observer_test_cases.sh # Run Python unit test based on the operations executed above python /test/directory_observer/tests/Dockerfile_testing/test_directory_observer.py cd /test/directory_observer/ && nosetests redis是监视器发现的事件存放的地方 directory_observer.py是目录监视器 directory_observer_test_cases.sh只是一个创build,重命名和移动一些文件和目录的bash脚本。 test_directory_observer.py只是一个Pythonunit testing脚本(在这里运行以进行debugging) 问题是一些testing失败没有任何明显的原因在构build,但如果我尝试从一个正在运行的容器完全相同的bash指令,它的工作原理。 如果你需要directory_observer_test_cases.sh的代码: #!/bin/bash cd /test/monitored1 […]

OSError:在Docker中初始化Celery时,权限被拒绝

运行docker撰写时,出现以下错误。 这个问题在我的Mac OS开发环境中完全没有发生(在Ubuntu和debian中尝试部署时发生这个错误),但是这个错误似乎表明Celery没有权限写入celerybeat文件。 我一直在努力试图让这个工作(试图给予芹菜必要的权限),但没有运气。 错误 celery_1 | [2017-06-17 13:08:26,509: INFO/Beat] beat: Starting… celery_1 | [2017-06-17 13:08:26,556: ERROR/Beat] Removing corrupted schedule file 'celerybeat-schedule': DBAccessError(13, 'Permission denied') celery_1 | Traceback (most recent call last): celery_1 | File "/usr/local/lib/python2.7/site-packages/celery/beat.py", line 376, in setup_schedule celery_1 | self._store = self._open_schedule() celery_1 | File "/usr/local/lib/python2.7/site-packages/celery/beat.py", line 366, in _open_schedule celery_1 | […]

如何在Docker中使用Liblas在Python中没有错误?

我正在尝试使用liblas来处理docker中的python中的一些激光雷达数据,但是我一直收到一个错误。 我试图运行的代码是从liblas python教程复制粘贴,并应该简单地创build一个las文件并写一个指向它: from liblas import file from liblas import header from liblas import point h = header.Header() # Support storing time values h.dataformat_id = 1 # Store a 1.1 version file h.minor_version = 1 f = file.File('test/junk.las', mode="w", header=h) pt = point.Point() f.write(pt) f.close() print 'The very very end' 当我尝试运行代码时,它似乎到了最后(它打印出'非常非常结束',但是然后它写入错误信息: *** Error in `python': […]

AttributeError:模块'wagtail.wagtailadmin.edit_handlers'没有属性'FieldPanel'

python3.6 w 1. 1.10.1几个小时前,我的基于w based的项目停止发射成功。 它在这里失败: from wagtail.wagtailadmin import edit_handlers print(dir(edit_handlers)) class Article(Page): html = RichTextField() content_panels = Page.content_panels + [ edit_handlers.FieldPanel('html', classname="full"), edit_handlers.InlinePanel('gallery', label="Carousel items", classname='ArticleImage'), ] 与错误 AttributeError: module 'wagtail.wagtailadmin.edit_handlers' has no attribute 'FieldPanel' 之后,我决定确保它不是我的环境和configuration的docker文件的错误: FROM python:latest ENV PYTHONUNBUFFERED 1 RUN mkdir /code WORKDIR /code ADD requirements.txt /code/ RUN pip install -r requirements.txt […]

运行python的Windows Docker容器中的证书validation错误

我刚开始使用python来利用第三方api来改善我们公司的工作stream程。 我一直在使用的一个API是citrix共享文件(一个安全的,pipe理的FTP服务器)。 我使用citrix编写的模块作为api调用的示例,因此在我正在编写的内容和实际的HTTP请求之间至less有一个抽象层。 当我做authentication请求从我的笔记本电脑获得一个访问令牌这工作得很好,但是当我尝试从一个docker容器(安装了Python的Windows nano)做同样的事情时,我得到了回来作为回应: Traceback (most recent call last): File "main.py", line 38, in <module> sharefile = pysharefile.authenticate(hostname,sf_client_id,sf_client_secret,sf_username,sf_password) File "C:\Python\lib\site-packages\pysharefile\pysharefile.py", line 42, in authenticate http.request('POST', uri_path, urllib.parse.urlencode(params), headers=headers) File "C:\Python\lib\http\client.py", line 1239, in request self._send_request(method, url, body, headers, encode_chunked) File "C:\Python\lib\http\client.py", line 1285, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "C:\Python\lib\http\client.py", line 1234, in endheaders self._send_output(message_body, […]

Docker无法安装numpy,scipy或gensim

我正在尝试构build一个Docker应用程序,该应用程序使用Python的gensim库,版本2.1.0,它是通过来自requirements.txt文件的pip安装的。 但是,Docker似乎在安装numpy,scipy和gensim时遇到了麻烦。 我GOOGLE了错误信息,发现其他用户经历了相同的问题,但在其他环境。 他们的许多解决scheme在Docker中似乎都不起作用。 以下是错误消息: <pre> Step 4 : RUN pip install -r requirements.txt —> Running in a86d07e229d7 Collecting Flask==0.12 (from -r requirements.txt (line 1)) Downloading Flask-0.12-py2.py3-none-any.whl (82kB) Collecting requests==2.17.3 (from -r requirements.txt (line 2)) Downloading requests-2.17.3-py2.py3-none-any.whl (87kB) Collecting numpy==1.12.1 (from -r requirements.txt (line 3)) Downloading numpy-1.12.1.zip (4.8MB) Collecting nltk==3.2.2 (from -r requirements.txt (line 4)) […]

在Docker容器上运行自主开发的Python服务器

我有这个python服务器: import SocketServer class TCPHandler(SocketServer.BaseRequestHandler): def handle(self): print 'client is connected' data = self.request.recv(1024) print data self.request.sendall('Message received!') HOST, PORT = '0.0.0.0', 5004 server = SocketServer.TCPServer((HOST, PORT), TCPHandler) print 'Listening on port {}'.format(PORT) server.serve_forever() 和这个客户: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('192.168.56.101', 5004)) s.sendall('Hello my name is John') response = s.recv(1024) print 'Response: {}'.format(response) 我的操作系统是macOS,我使用VirtualBox在虚拟机上安装了Ubuntu […]

Dockerfile包含一个写入输出文件的python脚本,但是输出文件没有在容器上创build

这是我的第一个问题,所以要温柔:) 我有一个Dockerfile如下: FROM centos:latest Maintainer Liz Miller LABEL description="Image Built with Dockerfile." RUN yum -y update RUN yum -y install python-setuptools RUN easy_install supervisor RUN mkdir -p /var/log/supervisor RUN yum -y install which RUN yum -y install git RUN yum install python COPY myscript.py myscript.py CMD ["python", "/myscript.py"] 而myscript.py python脚本是: text_file = open('output.txt', 'w') text_file.write('Hello […]

如何将数据从主机转发到Docker容器?

我正在使用Docker容器的项目。 Docker安装在Windows 10主机上。 该项目的目标是将主机上接收到的数据包转发到docker集装箱,以便集装箱function利用这些数据包并转发给其他链接的集装箱。 例如,考虑有2个容器(容器1和容器2)运行一些任意的function。 必须达到以下要求: Host(Windows 10)—–>Container 1——->Container 2——->Host 其中——>表示数据包转发(在容器function工作之后) 到目前为止,在刚收到数据包的主机上使用Wireshark接收数据包,并显示数据包的详细信息。 这些收到的数据包如何从主机,从一个容器转发到Docker容器? 可以使用Scapy(主机到容器)来完成吗? 我知道容器networking可以用来连接不同的容器,但是数据包可以在它们之间转发吗? 另外,在上述任何情况下,在主机和容器内部都可以使用python或java socket编程吗? 像libpcap这样的库可以用于这个目的吗?