Python Forum
Posting zip file on HTTP network using Python2.7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Posting zip file on HTTP network using Python2.7
#1
Hi,

We need to post a zip file on HTTP using Python 2.7.

We are using the below code which throwing exception:

post_data = open(zipPath,u'rb')
request = urllib2.Request(url,post_data.read().encode(u'utf-8'))
request.add_header(u"Content-Type", u"application/zip")
Please help.

Thanks and Regards
Reply
#2
We want to send a POST request, and in data we want to send .zip file
post_data = open(zipFilePath, 'rb')
readData = post_data.read()
headers = { 'Content-Type' : 'application/zip', 'Accept' : '*/*' }
url = "someURL"

#Python3.0
req = urllib.request.Request(url, post_data.read(), headers)
res = urllib.request.urlopen(req)

#Python2.7
req = urllib2.Request(url, post_data.read(), headers)
res = urllib2.urlopen(req)
We have observed that the value of 'readData' for the same zip file is different for Python 3 and Python 2.7
We want to read the zip file in Python 2.7 in the same exact way it's been read in Python 3.0, so that the zip file can be send in POST request using 'urllib2.urlopen()' function.

I have tried adding python tags but it seems I am doing something wrong. Sorry for inconvenience. Please help to understand the issue.

Thanks for your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Input network device connection info from data file edroche3rd 6 991 Oct-12-2023, 02:18 AM
Last Post: edroche3rd
  Python loop for posting data to web marciokoko 10 1,539 Aug-26-2023, 02:17 AM
Last Post: deanhystad
  Add http to a list on a text file Blue Dog 5 2,126 Sep-23-2021, 06:40 PM
Last Post: snippsat
  Failing to copy file from a network to a local drive tester_V 4 7,078 Jan-20-2021, 07:40 AM
Last Post: tester_V
  Code not reading http link from .txt file (Beginner level) plarrip 3 2,394 Dec-17-2020, 11:33 PM
Last Post: bowlofred
  Problem posting image to clipboard noel 0 2,153 Sep-26-2020, 10:50 AM
Last Post: noel
  ModuleNotFoundError: No module named 'http.client'; 'http' is not a package abhishek81py 1 15,387 Jun-25-2020, 08:58 AM
Last Post: buran
  Trying to run a python2 script dagamer1991 3 2,526 Aug-12-2019, 12:33 PM
Last Post: buran
  python2.7 executables thus the system python2.7 was erroring utility.execute()? vivekm 1 1,745 May-20-2019, 11:24 AM
Last Post: vivekm
  module logging posting randomly DJ_Qu 2 2,205 May-14-2019, 06:41 AM
Last Post: DJ_Qu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020