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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:28:23+00:00 2026-06-06T06:28:23+00:00

I have trouble doing this… You may want to get the same result as

  • 0

I have trouble doing this…

You may want to get the same result as in http://i.joyton.com:2010
Using this image.enter image description here, and other parameters keep default.

def search_img(item, image_name):
try:
    f = open(image_name, 'rb')
    img = f.read()
    print type(img)
except IOError, e:
    print 'fail to open %s' % image_name
    print e
    return None

ts = str(time.time())

m = md5.new('testsearch_by_image' + item)
m.update(ts)
m.update('0123456789')
sign = m.hexdigest()

params = urllib.urlencode( {
    'item': item,
    'app_key': 'test',
    'cmd':'search_by_image',
    'sign':sign,
    'img_file':img,
    'extra':'',
    'time_stamp':ts,
    })

headers = {'Content-type': 'application/x-www-form-urlencode',
           'Accept': 'text/plain'}

conn = httplib.HTTPConnection('i.joyton.com', 2010)
conn.request('POST', '', params, headers)
response = conn.getresponse()

print response.status, response.reason
print response.read()
conn.close()
return response.read()

if __name__ == '__main__':
    search_img('book', 'f:\\book_001.jpg')

In the browser everything works perfectly, but my script does not. Sometimes the script returns the right result; sometimes it gets other books, sometimes it gets nothing at all. When it gets other books, these books are usually searched by others recently.

  • 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-06T06:28:24+00:00Added an answer on June 6, 2026 at 6:28 am

    Here is your code modified to do a multipart/form-data. Although this didn’t work, when I tested at my PC against your URL, it probably needs some hacking (may be the sign isn’t proper or something) before you can get it to work.

    import mimetypes
    import string
    import random
    import time
    import md5
    import httplib
    
    def upload(fields,files):
        boundaryChars = list(string.lowercase) + list(string.uppercase) + \
                        [str(x) for x in range(10)] + ['_'*10]
        random.shuffle(boundaryChars)    
    
        boundary = '----------RaNdOm_crAPP'+''.join(boundaryChars[:20])
        CRLF = '\r\n'
        elem = []
        for key in fields:
            elem.append('--' + boundary)
            elem.append('Content-Disposition: form-data; name="%s"' % key)
            elem.append('')
            elem.append(fields[key])
        for (key, filename,value) in files:
            elem.append('--' + boundary)
            elem.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
            elem.append('Content-Type: %s' % mimetypes.guess_type(filename)[0] or \
                            'application/octet-stream')
            elem.append('')
            elem.append(value)
        elem.append('--' + boundary + '--')
        elem.append('')
        body = CRLF.join(elem)
        content_type = 'multipart/form-data; boundary=%s' % boundary
        return content_type, body
    
    def search_img(item, image_name):
        try:
            f = open(image_name, 'rb')
            img = f.read()
        except IOError, e:
            print 'fail to open %s' % image_name
            print e
            return None
    
        ts = str(time.time())
    
        m = md5.new('testsearch_by_image' + item)
        m.update(ts)
        m.update('0123456789')
        sign = m.hexdigest()
    
        #params = urllib.urlencode( )
    
        contentType,body = upload({
            'item': item,
            'app_key': 'test',
            'cmd':'search_by_image',
            'sign':sign,
            #'img_file':img,
            'extra':'',
            'time_stamp':ts,
            },
            [('img_file', image_name, img)]
        )
        headers = {
            'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Content-type': contentType,
            'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5',
            'Host':'i.joyton.com:2010',
            'Origin':'http://i.joyton.com:2010',
            'Referer':'http://i.joyton.com:2010/'
        }
        #print c
        #print body
    
        conn = httplib.HTTPConnection('i.joyton.com', 2010)
        conn.request('POST', '/', body, headers)
        response = conn.getresponse()
    
        print response.status, response.reason
        print response.read()
        conn.close()
        return response.read()
    
    if __name__ == '__main__':
        search_img('book', 'iMgXS.jpg') #the same image.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create hiscore list, but I have trouble doing it. This is
I'm having a bit of trouble doing some unit-testing using moq. If I have
I have trouble doing this. I'm creating a method that add working days on
I am having trouble doing a reverse URL lookup for Django-generated feeds. I have
I have trouble finding way to correctly refactor this code so that there would
I have trouble to expose a .NET assembly in COM. It seems that I
I have trouble using sed. I need to replace some lines in very deprecated
I have trouble parsing a HTML table using Nokogiri and Ruby. My HTML table
I'm using Entity Framework 4 and having trouble with a query. I have two
Basically, I am doing this: I have already read the database and obtained all

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.