久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Python urllib2 文件上傳問題

Python urllib2 file upload problems(Python urllib2 文件上傳問題)
本文介紹了Python urllib2 文件上傳問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我目前正在嘗試使用 urllib2 和 urllib2_file 啟動文件上傳圖書館.這是我的代碼:

I'm currently trying to initiate a file upload with urllib2 and the urllib2_file library. Here's my code:

import sys
import urllib2_file
import urllib2

URL='http://aquate.us/upload.php'
d = [('uploaded', open(sys.argv[1:]))]
req = urllib2.Request(URL, d)
u = urllib2.urlopen(req)
print u.read()

我已將此 .py 文件放在我的我的文檔"目錄中,并在我的發送到"文件夾中放置了一個快捷方式(快捷方式 URL 為 ).

I've placed this .py file in my My Documents directory and placed a shortcut to it in my Send To folder (the shortcut URL is ).

當我右鍵單擊一個文件,選擇發送到",然后選擇Aquate"(我的 Python)時,它會在瞬間打開一個命令提示符,然后將其關閉.什么都沒有上傳.

When I right click a file, choose Send To, and select Aquate (my python), it opens a command prompt for a split second and then closes it. Nothing gets uploaded.

我知道可能發生了錯誤,所以我將代碼逐行輸入到 CL python 中.當我運行 u=urllib2.urlopen(req) 行時,我沒有收到錯誤;替代文字 http://www.aquate.us/u/55245858877937182052.jpg

I knew there was probably an error going on so I typed the code into CL python, line by line. When I ran the u=urllib2.urlopen(req) line, I didn't get an error; alt text http://www.aquate.us/u/55245858877937182052.jpg

相反,光標只是在該行下方的新行上開始閃爍.我等了幾分鐘,看看是否會發生什么事情,但它就是這樣.為了讓它停止,我必須按 ctrl+break.

instead, the cursor simply started blinking on a new line beneath that line. I waited a couple of minutes to see if something would happen but it just stayed like that. To get it to stop, I had to press ctrl+break.

這個腳本是怎么回事?

提前致謝!

忘了提——當我在沒有請求數據(文件)的情況下運行腳本時,它運行起來就像一個魅力.是 urllib2_file 的問題嗎?

Forgot to mention -- when I ran the script without the request data (the file) it ran like a charm. Is it a problem with urllib2_file?

:

import MultipartPostHandler, urllib2, cookielib,sys
import win32clipboard as w
cookies = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies),MultipartPostHandler.MultipartPostHandler)
params = {"uploaded" : open("c:/cfoot.js") }
a=opener.open("http://www.aquate.us/upload.php", params)
text = a.read()
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardText(text)
w.CloseClipboard()

如果您通過命令行運行該代碼,它的作用就像一個魅力.

That code works like a charm if you run it through the command line.

推薦答案

如果您使用的是 Python 2.5 或更高版本,urllib2_file 既不必要也不支持,因此請檢查您使用的是哪個版本(并可能升級).

If you're using Python 2.5 or newer, urllib2_file is both unnecessary and unsupported, so check which version you're using (and perhaps upgrade).

如果您使用的是 Python 2.3 或 2.4(urllib2_file 支持的唯一版本),請嘗試運行 示例代碼 看看你是否有同樣的問題.如果是這樣,您的 Python 或 urllib2_file 安裝可能有問題.

If you're using Python 2.3 or 2.4 (the only versions supported by urllib2_file), try running the sample code and see if you have the same problem. If so, there is likely something wrong either with your Python or urllib2_file installation.

此外,您似乎沒有使用 urllib2_file 的兩種支持的 POST 數據格式.嘗試使用以下兩行中的 一個:

Also, you don't seem to be using either of urllib2_file's two supported formats for POST data. Try using one of the following two lines instead:

d = ['uploaded', open(sys.argv[1:])]
## --OR-- ##
d = {'uploaded': open(sys.argv[1:])}

這篇關于Python urllib2 文件上傳問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产精品久久午夜夜伦鲁鲁 | 久久久久国产一区二区三区 | 国产精品久久久久久久午夜片 | 久久6视频 | 91免费观看在线 | 91在线精品秘密一区二区 | 在线播放一区二区三区 | 国产超碰人人爽人人做人人爱 | 97精品国产97久久久久久免费 | 五月激情久久 | 久久成人免费视频 | 911网站大全在线观看 | 免费高清成人 | 91免费电影| 犬夜叉在线观看 | 一区二区视频在线 | 国产精品一码二码三码在线 | 精品国产三级 | 久久久免费在线观看 | 亚洲高清一区二区三区 | av色在线 | 欧美激情精品久久久久久免费 | 91中文字幕在线观看 | 国产亚洲精品精品国产亚洲综合 | 精品乱码一区二区 | 日韩中文一区 | 成人性视频免费网站 | 国产三级日本三级 | 久久久久久国产精品免费免费 | 中文字幕在线一区二区三区 | 黄色av大片 | 国产高清视频在线观看 | 亚洲视频手机在线 | 久久久久久亚洲精品 | 欧美一区二区三区国产精品 | 欧洲亚洲精品久久久久 | 久草综合在线 | 免费av直接看 | 日日夜夜天天久久 | 91黄在线观看 | 久久久久黑人 |