Zap Python - auto generation - zap

I've seen there is a python project and it states it's auto generated.
https://github.com/zaproxy/zap-api-python
What was used to generate python from java?

Its generated from java using this code: https://github.com/zaproxy/zaproxy/blob/develop/zap/src/main/java/org/zaproxy/zap/extension/api/PythonAPIGenerator.java

Related

Using custom java class in karate feature file [duplicate]

Good morning. I am working on a project that uses Karate Standalone. I am completely new to Karate to excuse my lack of knowledge here.
The standalone karate jar is executed with the '-m' command line parameter to start a mock.feature. The mock.feature references a utils class that is built on 'org.springframework.amqp'.
The problem is that the karate.jar startup fails with a Command Line Execution Exception due to external library 'org/springframework/amqp/rabbit/connection/ConnectionFactory'
api1_mock_test.feature
Feature: API1 Mock Test
Background:
* def RabbitUtils = Java.type('utils.RabbitUtils')
.
.
Our RabbitUtils is just a java class that imports org.springframework.amqp external libraries to provide functions to interact with a Rabbit AMQP broker e.g. connect, receive, publish, purge etc. When built and run in IntelliJ all works ok. The POM reference in the project is:
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
Does the Karate standalone jar have some way of referencing external libraries? The classpath parameter is set to reference our workspace '.\target\test-classes' and contains the RabbitUtils.class file.
The current execution from workspace root looks like this:
java -jar C:\intuit\karate-0.9.3.RC2.jar -cp .\target\test-classes -p 6868 -m .\src\test\java\mocks\api1_mock_test.feature
08:57:05.122 [main] INFO com.intuit.karate.Main - Karate version: 0.9.3.RC2
08:57:05.891 [main] ERROR com.intuit.karate - server-side background init failed - api1_mock_test.feature:4
Exception in thread "main" picocli.CommandLine$ExecutionException:
-unknown-:4 - org/springframework/amqp/rabbit/connection/ConnectionFactory
Thank you!
Thanks for asking this, and I think I've figured out a way to do this which opens up a lot of great possibilities. The solution is to use Java first-principles, and not use the -jar option. The Karate command-line-app (or CLI) class happens to be com.intuit.karate.Main. I'm going to provide a demo here of using SikuliX. First, the feature file test.feature:
Feature: sikuli test
Background:
* def Screen = Java.type('org.sikuli.script.Screen')
Scenario:
* def s = new Screen()
* def c = s.capture()
* c.getFile('.')
And with the karate.jar and sikulixapi.jar in the same folder on the command line, this works (for windows, use ; instead of : as the "path separator"):
java -cp karate.jar:sikulixapi.jar com.intuit.karate.Main test.feature
For those looking to customize the classpath for the Visual Studio Code "Karate Runner" extension, please refer this: https://github.com/intuit/karate/wiki/Karate-Robot-Windows-Install-Guide#change-command-line-settings
Also see: https://stackoverflow.com/a/58398958/143475
For those who really don't want to compile Java but need to use some JVM libraries, it is possible via pure JS, (but hard to troubleshoot and debug): https://stackoverflow.com/a/65035825/143475

Google Speech API cannot import name 'enums'

I am trying to use Google Speech API to recognize speech, on windows with colab
here is the error
ImportError: cannot import name 'enums' from 'google.cloud.speech_v1'
Anybody knows how to solve this?
Looks like in the new version they have removed enums. Check this link, If you want enums then you have to switch to an old version.
As mentioned in #addno1's answer, enums and types have been removed in the 2.x versions of the library. It seems that you are using a 2.x version of the library, hence the error.
If your code is using the 1.x version of the library and if you would like to upgrade to the latest version of the library, refer to this migration guide(same mentioned in the other answer). You can refer to this quick start for setup instructions and an updated client library code given below.
# Imports the Google Cloud client library
from google.cloud import speech
# Instantiates a client
client = speech.SpeechClient()
# The name of the audio file to transcribe
gcs_uri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw"
audio = speech.RecognitionAudio(uri=gcs_uri)
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=16000,
language_code="en-US",
)
# Detects speech in the audio file
response = client.recognize(config=config, audio=audio)
for result in response.results:
print("Transcript: {}".format(result.alternatives[0].transcript))
If you want to use the older code, you will have to downgrade the library version to 1.3.2 (last 1.x version) by running the pip command
pip install google-cloud-speech==1.3.2

Cannot create Groove Script on Intellij - Argument for #NotNull parameter

I am trying to start learning Groovy for perform API calls using ScriptRunner on JIRA. So I am starting from the basics.
My problem is that I cannot even create a Groovy script using Intellij. At the project creation it am selecting Groovy and choosing for project SDK version 16.0.2 and Groovy Library groovy-3.0.8
Once the project is created and I try to create the script, the IDE send me the following error message:
Argument for #NotNull parameter 'rootTypes' of com/intellij/openapi/roots/impl/ProjectFileIndexImpl.isUnderSourceRootOfType must not be null
Does anyone know why I am getting this error message?

Installed gurobi , not refelecting when importing

I have installed gurobi, however it does not get reflected when importing.
I get the following error:
No module name gurobi
You didn't write which API you are using. If you are using python, you should use import gurobipy and not gurobi. You also need to setup some environment variables (GUROBI_HOME, PATH and LD_LIBRARY_PATH). See Gurobi quick start guide.

Reg Jython Python wrap for Java

I have been assigned a task to convert a java standalone application to python web application.Recoding the entire module in python language would take a lot of time and effort.Hence I was adviced do a quick wrap up of python and get the code working (jython.org) (Jython is Python wrap for JAVA )..Could any one guide me how to get started as I am new to Python as well as Jython?
To get you started:
If you're familiar with Java, then you should be able to get to the Jython prompt no problem. Just execute it like any other .jar. If you didn't download the standalone jython.jar, be sure to include the Jython libraries in your classpath.
Say your Java application's package is named com.stackoverflow.q10715162, and is compiled as a .jar in C:\jars\your_app.jar.
Then, you can get access to its classes in Jython. At the Jython prompt:
>>> import sys
>>> sys.path
['', 'C:\\jython\\Lib', 'C:\\jython\\jython.jar\\Lib', '__classpath__',
'__pyclasspath__']
Here, sys.path is, among other things, a list of directories where your Jython distribution is looking for compiled modules. By adding your compiled Java application to the list, it will become accessible (more in-depth info is available for this at http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html):
>>> sys.path.append('C:\\jars\\your_app.jar')
>>> import com.stackoverflow.q10715162 as yourapp
*sys-package-mgr*: processing new jar, 'C:\\jars\\your_app.jar'
>>> dir(yourapp)
['Class1', 'Class2', 'Class3', ...]
By using dir(yourapp) you can see the classes you defined in your Java application. dir(yourapp.Class1) will list all methods, functions, etc. that are within the class.
You probably want to read through the first few pages at least of the Jython Book to familiarize yourself with the new syntax. I find it much simpler than Java's.
For making a Jython web app, I've heard cgi is by far the fastet way to get started with the least overhead:
#!/usr/bin/python
print("Content-Type: text/plain\n\n")
print("Hello, World!\n")
This tutorial seems helpful: http://www.cs.virginia.edu/~lab2q/lesson_1/. Although it is for Python, almost all of it should be applicable to Jython.
And of course, there are many other Python/Jython web service options if cgi doesn't suit you or your project. I've used web2py and really liked it.