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

  • SEARCH
  • Home
  • 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 7807207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:46:53+00:00 2026-06-02T02:46:53+00:00

I have a problem with this snippet of code: import optparse parser = optparse.OptionParser(version=__version__,

  • 0

I have a problem with this snippet of code:

import optparse
parser = optparse.OptionParser(version=__version__,
    usage="%prog [options] file1 ... host[:dest]",
    description=main.__doc__)
parser.add_option("-c", "--config", help="Specify an alternate config "
    "file.  Default = '%s'" % config_file)
parser.add_option('-l', '--log-level', type="choice",
    choices=LOG_LEVELS.keys(),
    help="Override the default logging level. Choices=%s, Default=%s" %
        (",".join(LOG_LEVELS.keys()), LOG_LEVEL))
parser.add_option("-o", "--overwrite", action="store_true",
    help="If specified, overwrite existing files at destination.  If "
    "not specified, throw an exception if you try to overwrite a file")
parser.add_option('-s', "--speed", action="store_true", \
    help="If specifed, print the data transfer rate for each file "
        "that is uploaded (infers verbose option)")
parser.add_option('-v', '--verbose', action="store_true",
    help="If specified, print every file that is being uploaded and every "
        "directory that is being created")
parser.add_option("-u", "--user", help="The username to use for "
    "authentication.  Not needed if you have set up a config file.")
parser.add_option("-p", "--password", help="The password to use for "
    "authentication.  Not needed if you have set up a config file.")

parser.set_defaults(config=config_file, log_level=LOG_LEVEL)
options, args = parser.parse_args()
print (args)

As you can see, when I print the args of a test we are doing with hebrew named file, the print result includes: [‘/root/mezeo_sdk/1/\xfa\xe5\xeb\xf0\xe9\xfa \xf2\xe1\xe5\xe3\xe4.xlsx’, ‘hostname’]
Instead of /root/mezeo_sdk/1/”תוכנית עבודה.xlsx”

Also, the end result once the script uploads the file to the server (the way the filename was passed) is: https://i.stack.imgur.com/JC1rt.png

The filename itself is good on the linux source, because if I SCP it to my own computer it looks ok, but not once I transfer it to the file server using the python script.

I also dont believe the problem is on the file server side, because if I use the web interface to upload hebrew named files, they are OK.

I think the problem is with the usage of optparse library.

  • 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-02T02:46:54+00:00Added an answer on June 2, 2026 at 2:46 am

    As always, I’ll start with the Unicode suggested reading: you should really read either or both of

    • Pragmatic Unicode (Ned Batchelder)
    • The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) (Joel Spolsky)

    In a (very small) nutshell, a Unicode code point is an abstract “thingy” representing one character1. Programmers like to work with these, because we like to think of strings as coming one character at a time. Unfortunately, it was decreed a long time ago that a character must fit in one byte of memory, so there can be at most 256 different characters. Which is fine for plain English, but doesn’t work for anything else. There’s a global list of code points — thousands of them — which are meant to hold every possible character, but clearly they don’t fit in a byte.

    The solution: there is a difference between the ordered list of code points that make a string, and its encoding as a sequence of bytes. You have to be clear whenever you work with a string which of these forms it should be in. To convert between the forms you can .encode() a list of code points (a Unicode string) as a list of bytes, and .decode() bytes into a list of code points. To do so, you need to know how to map code points into bytes and vice versa, which is the encoding.

    1Sort of.


    OK, now that that’s out of the way, let’s look at what you have. You have given a (raw) string — a sequence of bytes:

    \xfa\xe5\xeb\xf0\xe9\xfa \xf2\xe1\xe5\xe3\xe4
    

    which you would like to be the encoding of

    תוכנית עבודה
    

    A little bit of Googling tells me that you are using the Windows-1255 encoding, which is an extension of ASCII using the upper bytes to hold Hebrew letters. You want to have the string in Unicode, because Unicode represents normal data. So, you should decode the sequence of bytes, using the encoding "Windows-1255":

    >>> s
    '\xfa\xe5\xeb\xf0\xe9\xfa \xf2\xe1\xe5\xe3\xe4'
    >>> s.decode("Windows-1255")
    u'\u05ea\u05d5\u05db\u05e0\u05d9\u05ea \u05e2\u05d1\u05d5\u05d3\u05d4'
    

    Now you have the right sort of data. Next, you need to send the data to the server, which means encoding it in a normal encoding, namely “UTF-8”:

    >>> s.decode("Windows-1255").encode("utf-8")
    '\xd7\xaa\xd7\x95\xd7\x9b\xd7\xa0\xd7\x99\xd7\xaa \xd7\xa2\xd7\x91\xd7\x95\xd7\x93\xd7\x94'
    

    Finally, you may wonder where the server went wrong. Well, if you don’t specify an encoding for data people will have to guess, which is an enterprise doomed to failure. In your case, it looks like you sent the raw bytes to the server, which then decoded them as latin-1. That gives the weird accented letters you see, because latin-1 uses the upper half of the ASCII bytes not for Hebrew characters but for accented English ones.

    Moral of the story: understand Unicode!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when I run this snippet of code on the emulator
Never thought I'd have this problem :) The following snippet of code works in
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
Hi i have problem with this code, i found it on the internet and
i am a beginner and i have a problem : this code doesnt compile
For example I have this snippet of html code: ..... <span class=no> 1</span> require
Have a look to this code snippet:- -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [webData setLength:
Hi I have my mvc app and this code snippet: protected override void OnException(ExceptionContext
I have problem thinking this trough with PHP & Mysql . I have read

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.