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 2,611 Oct-12-2023, 02:18 AM
Last Post: edroche3rd
  Python loop for posting data to web marciokoko 10 3,297 Aug-26-2023, 02:17 AM
Last Post: deanhystad
  Add http to a list on a text file Blue Dog 5 3,148 Sep-23-2021, 06:40 PM
Last Post: snippsat
  Failing to copy file from a network to a local drive tester_V 4 10,062 Jan-20-2021, 07:40 AM
Last Post: tester_V
  python2 python3 messed up : How to fix ? hary 15 11,239 Dec-30-2020, 08:26 PM
Last Post: hary
  Code not reading http link from .txt file (Beginner level) plarrip 3 3,206 Dec-17-2020, 11:33 PM
Last Post: bowlofred
  Problem posting image to clipboard noel 0 3,026 Sep-26-2020, 10:50 AM
Last Post: noel
  using pudb on python2 code ErnestTBass 2 2,368 Aug-10-2020, 08:12 PM
Last Post: snippsat
  ModuleNotFoundError: No module named 'http.client'; 'http' is not a package abhishek81py 1 18,105 Jun-25-2020, 08:58 AM
Last Post: buran
  Trying to run a python2 script dagamer1991 3 3,323 Aug-12-2019, 12:33 PM
Last Post: buran

Forum Jump:

User Panel Messages

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