Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用多个文件和线程队列尝试HTTP Post的权限被拒绝_Python_Multithreading_Http_Upload_Queue - Fatal编程技术网

Python 使用多个文件和线程队列尝试HTTP Post的权限被拒绝

Python 使用多个文件和线程队列尝试HTTP Post的权限被拒绝,python,multithreading,http,upload,queue,Python,Multithreading,Http,Upload,Queue,我有一个应用程序(通常)一次只能尝试一个http post一个或两个文件,但最终可能会有大量文件需要上传(基于文件大小/网速)。我想我可以尝试一个线程队列系统,这样用户可以继续填充队列,而在后台,线程队列会仔细检查要发送的文件 我试图用屠夫来干活,但没用 这是我的密码: import threading, urllib2, Queue, os from poster.encode import multipart_encode from poster.streaminghttp import r

我有一个应用程序(通常)一次只能尝试一个http post一个或两个文件,但最终可能会有大量文件需要上传(基于文件大小/网速)。我想我可以尝试一个线程队列系统,这样用户可以继续填充队列,而在后台,线程队列会仔细检查要发送的文件

我试图用屠夫来干活,但没用

这是我的密码:

import threading, urllib2, Queue, os
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers

path = "path/to/files/"

urls_to_load = [os.path.join(path,x) for x in os.listdir(path)]

def read_url(file, queue):
    register_openers()
    datagen, headers = multipart_encode({"myfile": open(file, "rb")})
    request = urllib2.Request("http://localhost/appname/upload", datagen, headers)
    queue.put(urllib2.urlopen(request).read())

def fetch_parallel():
    result = Queue.Queue()
    threads = [threading.Thread(target=read_url, args = (url,result)) for url in urls_to_load]
    for t in threads:
        t.start()
    for t in threads:
        t.join()
    return result

result = Queue.Queue()
for url in urls_to_load:
    read_url(url,result)
print result
但是,我遇到了一个权限错误:

Traceback (most recent call last):
  File "C:/Users/tmiller/Desktop/multiBro.py", line 78, in <module>
    datagen, headers = multipart_encode({"myfile": open(i, "rb")})
IOError: [Errno 13] Permission denied: 'the file'
回溯(最近一次呼叫最后一次):
文件“C:/Users/tmiller/Desktop/multiBro.py”,第78行,在
datagen,headers=multipart_encode({“myfile”:open(i,“rb”)})
IOError:[Errno 13]权限被拒绝:“文件”
我假设有一些访问冲突正在发生,但我该如何防止呢


web服务器实际上正在运行一个。谢谢

您之前说过您在使用HTTPPOST——您现在正在使用GET吗?结果是我从web.py示例中取出了GET代码,因此没有返回数据。没有得到错误,但是现在情况已经改变,我在文件上得到一个权限被拒绝的错误。更新OP以反映