[Sikuli-driver] [Question #262180]: How i can import json module in my scripts
New question #262180 on Sikuli: https://answers.launchpad.net/sikuli/+question/262180 I try in my script to import a module for working with json. But I have some reason it does not work. I tried to import json_simple-1.1.jar through the load (jar), but I encounter the error that json is not revealed. I also know that we can somehow set https://pypi.python.org/pypi/simplejson/ but I do not know how to do so I do not have a pure Python . I run my script through the command line: java -jar% SIKULI_HOME% \ sikuli-script.jar path-to-your-script \ yourScript.sikuly Tell me how do I import module for work with Json -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Open => Answered RaiMan proposed the following answer: this simplejson Python module does not work with Jython, because it has C-based parts. It is said, that Jython 2.7 has json support built in (we use Jython 2.7 in version 1.1.0). Another option is to use jyson (http://opensource.xhaus.com/projects/jyson) -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Answered => Open Chp is still having a problem: Thank you very much for the quick response. I have a version of Sikuli Script X-1.0rc3. I wanted to upgrade to Sikuli 1.1, but I stopped because not working there sending requests from the module urllib2. Is there any way in version Sikuli Script X-1.0rc3 then get to work with json_simple-1.1.jar? -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Chp gave more information on the question: I just do not get how to connect or jar packages -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Open => Answered RaiMan proposed the following answer: What problems do you have with urllib2 in version 1.1.0? Using stuff in provided in jars: - take care, that the respective jar is on the Java class path at runtime (option -cp with the java.exe, look into the sikuliā¦bat) - in Jython script just add imports naming the complete class path for the given stuff example: import org.sikuli.script.Region as SikReg # creates a shortcut some_region = SikReg(0, 0, 100, 100) You have to adapt this to your json jar case. -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Answered => Open Chp is still having a problem: I am sorry that I could not answer you right away. What problems do you have with urllib2 in version 1.1.0? --> In my tests I need to constantly send requests to the server to install or get some data. Here is my code: def delete(self, User): API.log('Admin user delete:') params = { 'authenticity_token':self.authenticity_token, '_method' :'delete', } data = urllib.urlencode(params) url = self.url+'/users/'+User.dict['dw_id']+'/game_data' self.go_url(url, data) API.log('Admin user delete DONE!') @trust_all_certificates def go_url(self, url, data = None, headers = {}): request = urllib2.Request(url, data, headers) try: response = self.opener.open(request) except IOError, e: if hasattr(e, 'reason'): self.game.error('We failed to reach a server. Reason: '+str(e.reason)) elif hasattr(e, 'code'): self.game.error('The server couldn\'t fulfill the request. Error code: '+str(e.code)) return response On jython2.5.2 it works well, but sometimes in jython 2.7 (not always), an error: ERROR: We failed to reach a server. Reason: [Errno 32] Illegal state exception The problem I could not fix. Now try to download the jar file, if that otpishus -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Chp gave more information on the question: I no it does not get imported jar package, please help! I run my script from the command line: "cmd": ["C:\\Program Files (x86)\\Java\\jre6\\bin\\java.exe", "-jar", "C:\\Program Files (x86)\\Sikuli X\\sikuli-script.jar", "$file_path"] "$file_path" = D:\autotest\dragon_world\TestCases\Test\Test.sikuli my file structure: http://joxi.ru/QY2LlG5i75ey26 http://joxi.ru/lbrRgbZi7vnQm1 http://joxi.ru/L4AkLxqCoqKjrq my code: # coding=cp1251 from os.path import dirname,join from os import putenv TEST_DIR = dirname(dirname(dirname(getBundlePath( ROOT_DIR = dirname(TEST_DIR) putenv('TEST_DIR', TEST_DIR) putenv('ROOT_DIR', ROOT_DIR) sys.path.append(TEST_DIR) sys.path.append(ROOT_DIR) sys.path.append("""D:\\autotest\Core\json-simple.jar""") from Core import Common from TestCases.DW import DW print('TEST_DIR',TEST_DIR) print('ROOT_DIR',ROOT_DIR) print('SYS.PATH',sys.path) import org.json.simple.parser exit(0) trace: [info] Sikuli vision engine loaded. [info] Windows utilities loaded. [info] VDictProxy loaded. Check log dir D:\autotest\dragon_world\Log\2015_02_18 ('TEST_DIR', u'D:\\autotest\\dragon_world') ('ROOT_DIR', u'D:\\autotest') ('SYS.PATH', ['C:\\Program Files (x86)\\Sikuli X\\Lib', 'C:\\Program Files (x86)\\Sikuli X\\sikuli-script.jar\\Lib', '__classpath__', '__pyclasspath__/', 'D:/autotest/dragon_world/TestCases/Test/Test.sikuli/', 'D:/autotest/dragon_world/TestCases/Test/', u'D:\\autotest\\dragon_world', u'D:\\autotest', 'D:\\autotest\\Core\\json-simple.jar', '.']) [error] Can't run this Sikuli script: D:\autotest\dragon_world\TestCases\Test\Test.sikuli ERROR: File "D:\autotest\dragon_world\TestCases\Test\Test.sikuli\Test.py", line 22, in import org.json.simple.parser No module named json [screenshot]20150218_131037.jpg[/screenshot] [error] Can't run this Sikuli script: home=1java.lang.StringIndexOutOfBoundsException: String index out of range: -1 [error] Can't run this Sikuli script: eoe=1 at java.lang.String.substring(Unknown Source) at org.sikuli.script.ScriptRunner.getPyFrom(ScriptRunner.java:109) at org.sikuli.script.ScriptRunner.runPython(ScriptRunner.java:103) at org.sikuli.script.SikuliScript.main(SikuliScript.java:115) java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(Unknown Source) at org.sikuli.script.ScriptRunner.getPyFrom(ScriptRunner.java:109) at org.sikuli.script.ScriptRunner.runPython(ScriptRunner.java:103) at org.sikuli.script.SikuliScript.main(SikuliScript.java:115) [Finished in 5.6s] -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Open => Answered RaiMan proposed the following answer: the json jar must be on the Java class path: "cmd": ["C:\\Program Files (x86)\\Java\\jre6\\bin\\java.exe", "-jar", "-cp", "D:\\autotest\Core\json-simple.jar", "C:\\Program Files (x86)\\Sikuli X\\sikuli-script.jar", "$file_path"] -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Answered => Open Chp is still having a problem: Does not work, nothing works, I do not know how I continue to be. ( -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Open => Answered RaiMan proposed the following answer: If you want the parser in the script: import org.json.simple.parser.JSONParser as JSP parser = JSP() parser.parse(someReader) someReader must be a reader object of java.io.reader (e.g. FileReader()) But I guess the path you selected is to much Java based. You should use a solution that is Jython based. e.g. jyson (http://opensource.xhaus.com/projects/jyson) it is well documented and written for use with Jython. -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Answered => Solved Chp confirmed that the question is solved: Thanks RaiMan, that solved my question. -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Solved => Open Chp is still having a problem: I really did not need to do "-cp", "D: \\ autotest \ Core \ json-simple.jar" It turns out do not work: import org.json.simple.parser Needs to be done: from org.json.simple.parser import JSONParser))) And you do not know why jython 2.7 error occurs that I described above? ERROR: We failed to reach a server. Reason: [Errno 32] Illegal state exception -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp
Re: [Sikuli-driver] [Question #262180]: How i can import json module in my scripts
Question #262180 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/262180 Status: Open => Expired Launchpad Janitor expired the question: This question was expired because it remained in the 'Open' state without activity for the last 15 days. -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. ___ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp