Encoding sys.argv in python 2.7 -


i'm writing script takes input software (maltego), , using sys.argv[1] variable. when information maltego in hebrew, question marks rather actual text. tried encoding text in different ways failed.

i'm using python 2.7.

any idea solution appreciated.

the script being run within maltego:

# -*- coding: utf-8 -*-  import time selenium import webdriver selenium.webdriver.common.keys import keys bs4 import beautifulsoup maltegotransform import * import codecs import sys reload(sys) sys.setdefaultencoding('utf-8')   me = maltegotransform() search_value = sys.argv[1].encode("utf-8") 

here fifty pence:

import sys   def win32_utf8_argv():     """uses shell32.getcommandlineargvw sys.argv list of utf-8     strings.      versions 2.5 , older of python don't support unicode in sys.argv on     windows, underlying windows api instead replacing multi-byte     characters '?'.      returns none on failure.       """      try:         ctypes import pointer, byref, cdll, c_int, windll         ctypes.wintypes import lpcwstr, lpwstr          getcommandlinew = cdll.kernel32.getcommandlinew         getcommandlinew.argtypes = []         getcommandlinew.restype = lpcwstr          commandlinetoargvw = windll.shell32.commandlinetoargvw         commandlinetoargvw.argtypes = [lpcwstr, pointer(c_int)]         commandlinetoargvw.restype = pointer(lpwstr)          cmd = getcommandlinew()         argc = c_int(0)         argv = commandlinetoargvw(cmd, byref(argc))         if argc.value > 0:             # remove python executable if present             if argc.value - len(sys.argv) == 1:                 start = 1             else:                 start = 0             return [argv[i].encode('utf-8') in                     xrange(start, argc.value)]     except exception:         pass  if __name__ == '__main__':     = win32_utf8_argv()     print (a[1]) 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -