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 7733617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:02:30+00:00 2026-06-01T07:02:30+00:00

I know this looks embarrassingly easy, and I guess the problem is that I

  • 0

I know this looks embarrassingly easy, and I guess the problem is that I just don’t have a clear understanding of all this bytes-str-unicode (and encoding-decoding, speaking frankly) stuff yet.

I’ve been trying to get my working code to run on Python 3. The part I’m stuck with is when I parse an XML with lxml and decode a base64 string that is in that XML.

The code now works in the following manner:

I retrieve the binary data with an XPath query '.../binary/text()'. This produces a one-element list containing a lxml.etree._ElementUnicodeResult object. Then, with python 2, I was able to do:

decoded = source.decode('base64')

and finally

output = numpy.frombuffer(decoded)

However, on python 3 I get an error message saying

AttributeError: 'lxml.etree._ElementUnicodeResult' object has no attribute 'decode'

This is not so surprising, because lxml.etree._ElementUnicodeResult is a subclass of str.

Another way would be to get a real str with the same data in it with

 binary = tree.xpath('//binary')[0]
 binary_string = binary.text

That would be essentially the same. So what do I do to decode it from base64? I’ve looked at the base64 module, but it takes a bytes object as an argument, and I can’t think of the way to present str as bytes, because if I try to construct a bytes object, Python will try to encode the string, which I don’t need.

Googling further, I came across the binascii module (which is invoked indirectly from base64 anyway, if I’m not mistaken), but calling binascii.b2a_base64() on my string produces

TypeError: 'str' does not support the buffer interface

P.S. I’ve even found an answered question on how to decode a hex string in Python 3, but this is done with a dedicated method bytes.fromhex() so I don’t see how it would be helpful.

Could someone please tell me what I’m missing? I’m afraid most of the post is irrelevant and only aggravates my shame, but at least you guys know what I tried.

  • 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-01T07:02:32+00:00Added an answer on June 1, 2026 at 7:02 am

    I don’t have Python 3 installed, but it sounds like you need to convert the Unicode returned from lxml to bytes, perhaps by calling .encode(‘ascii’) ?

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

Sidebar

Related Questions

I want to know what this looks like. I don't have any ideas about
I don't know where to look for about this problem ... I have three
i know that this question looks the same as other around here, but none
I have a table that looks like this: id datatype name value 0 nvarchar(255)
I have Delphi 2007 code that looks like this: procedure WriteString(Stream: TFileStream; var SourceBuffer:
Okay. I know this looks like the typical Why didn't he just Google it
I know this looks similar to other questions here but I don't think my
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
I have a data set that looks like this: ByYear <- data.frame( V1 =
I know this looks a bit long but i tried to explain the problem

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.