Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9148067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:10:18+00:00 2026-06-17T11:10:18+00:00

When I download a file from my server using Python and urlib2, the files

  • 0

When I download a file from my server using Python and urlib2, the files contents are slightly different than what they should be.

They are different in that there are extra lines(“\r\n” or “\n”) added to the downloaded version of the file. This isn’t a major problem for a file that is in xml form but its a major problem when my file is encrypted because the file contents are slightly different and they cant be decrypted.

I know its my download code thats altering the file contents and not the file thats on the server being wrong because I have downloaded that file using FTP and found it has the correct content when I download it that way. Some more useful information: the file is ASCII encoded. My server is Windows .NET and I’m unsure if the http response is ascii or unicode – maybe that could be causing the problem?

How can I make urlib2 download my file from my server and ensure that the content doesn’t change?

Original content:

     <clientlist>


       <client>
         <clientauthblah>blah</clientauthblah>
         <version9>blah</version9>
         <version10>blah</version10>
         <companyno>1</companyno>
         <companyname>blah</companyname>
       </client>

When I run my download code this is the content I get, this is something I cant have because my files are encrypted and it means I cant decrypt the file:

 <clientlist>




   <client>

     <clientauthblah>blah</clientauthblah>

     <version9>blah</version9>

     <version10>blah</version10>

     <companyno>1</companyno>

     <companyname>blah</companyname>

   </client>

Heres my code:

# Download
response = urllib2.urlopen("http://www.mywebsite.com/Clients.xml")
output    = open("tempEncrypted.xml",'w')
res       = response.read()
output.write(res)
output.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:10:21+00:00Added an answer on June 17, 2026 at 11:10 am

    The problem here is this line:

    output    = open("tempEncrypted.xml",'w')
    

    Python opens files in text mode by default, which means you may get newline conversions. The details are complicated by platform differences, universal newlines, etc.

    But if you have binary data, the answer is simple: open it in binary mode, by using 'wb' instead of 'w':

    output    = open("tempEncrypted.xml",'wb')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using python to programatically download a zip file from a web server. Using
I'm trying to download a zip-file from a server. For that I'm using the
I am trying to implement an Asynchronous file download from a web server using
I'm using ftp_put() to download a file from another server. Everything (connection etc.) working
Explain me please how to download a file from a server using SSL (https://).
I am trying to download a file from an FTP server using an NSOperation.
I am using GWT. I have to download a file file from server to
I need to download a .mp3 or .m4a file from the server by using
I am using python ftplib to download builds from the builds ftp server. The
i'm trying to download file from http server using WinINet library calls. It works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.