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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:57:12+00:00 2026-05-25T21:57:12+00:00

This is a follow on from: Python – Converting Hex to INT/CHAR I now

  • 0

This is a follow on from: Python – Converting Hex to INT/CHAR

I now have a working solution for converting the stored hex value of an IP from an sqlite3 db into a readable and usable format. However up until now I have been testing by copying and pasting the values directly from a sqlite3 db viewer.

I have been trying to poll the db with a script to lookup that information however I have discovered that it apparantly stores blob data into a buffer which isn’t instantly human readable.

For example, the IP 192.168.0.1 is stored as blob type under the field ip as X’C0A80001′

Since I worked from a copied and pasted example into my code I have constructed code to strip the X’ and ‘ from the hex to be able to then convert it. What I cannot get is that value from the database (X’C0A80001’ <- this value that I can view with a db manager).
Searching I found http://eli.thegreenplace.net/2009/05/29/storing-blobs-in-a-sqlite-db-with-pythonpysqlite/ which showed an example of reading blobs to and from a sqlite db but their methods didn’t work. They displayed the error;

print row[0], str(row[1]).encode('hex')
IndexError: tuple index out of range

I am fairly new to Python so apologies if I am missing something basic but any pointers or code examples anyone has to help me get my head around this would be appreciated.

EDIT:
Doh, didn’t paste the code from the above example;

c = conn.cursor()
c.execute('select ip from item where name = ' + "\'" + host + "\'")
for row in c:
        print row[0], str(row[1]).encode('hex')

It may be my understanding thats really off here as to why I can’t read it back the way I want to

UPDATE:
Using the below answer I modified my code to;

rows = c.execute('select ip from item where name= ' + "\"" + host + "\"") 
   for row in rows:
       print str(row[0]).encode("hex")
  • 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-05-25T21:57:13+00:00Added an answer on May 25, 2026 at 9:57 pm

    After checking the link, it seems the most likely explanation is an empty row. On line 29 you set up a for loop to go over the results of a query. In python this means you have a list:
    [item,item2,item3] and each time you go through the loop, your row variable points to the next item.

    Within the loop, you are checking the contents of the current item. Each of these items is a tuple which suppposedly has at least two entries. But if any of those items don’t have an entry for row[0] or row[1] then you will get an index out of range exception.

    You haven’t posted enough code to make determining why this occurred feasible, but to get the code running I’d suggest this:

    for row in cur.execute("select * from frames"):
        try:
            print row[0], str(row[1]).encode('hex') 
        except IndexError, e:
            print "IndexError: {0}".format(e)
    

    That will continue across your entire query result, even if some of them are bad.

    Edit: I just saw your update, and your problem is that c does not hold the contents of your query. c.execute('select ip from item where name = ' + "\'" + host + "\'") returns a list, which you ignore.

    The original example works because you get the list in the for loop, and so it’s an anonymous variable only within the loop context. To fix your code:

    c = conn.cursor()
    rows = c.execute('select ip from item where name = ' + "\'" + host + "\'")
    for row in rows:
            print row[0], str(row[1]).encode('hex')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow-up to my question from yesterday . I have Scott Meyers'
Does anyone know how to convert this function from Python to PHP? I have
This is a follow up from a question of mine that was just answered
This is a follow on from my previous question although this is about something
This is a follow-on from this question, in which I was trying to suppress
I am trying to follow this example (from p137 of Rob Pickering's Foundations of
This question is a follow-up from How to indicate that a method was unsuccessful
This is a follow-on question from the one I asked here . Can constraints
This question is a follow on from this one ... I am binding to
This is a follow on question to How do I delete 1 file from

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.