Token Parsing Error: Lexical error - jmeter

I am getting the following error when I use a BeanshellPostProcessor to regex some data and write to file:
2015/06/11 12:11:19 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: `` import java.io.FileOutputStream; import java.util.Map; import java.u . . . '' Token Parsing Error: Lexical error at line 10, column 45. Encountered: "d" (100), after : "\"c:\\"
2015/06/11 12:11:19 WARN - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: `` import java.io.FileOutputStream; import java.util.Map; import java.u . . . '' Token Parsing Error: Lexical error at line 10, column 45. Encountered: "d" (100), after : "\"c:\\"
My code:
import java.io.FileOutputStream;
import java.util.Map;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.*;
String entirePage = new String(data);
FileWriter fstream = new FileWriter("c:\\downloads\\results.txt",true);
BufferedWriter out = new BufferedWriter(fstream);
Pattern totalNetValue = Pattern.compile("totalNetValue\">([^\"]+)</span>");
Matcher mTotalNetValue = totalNetValue.matcher(entirePage);
mTotalNetValue.find();
//out.write(${date});
out.write(mTotalNetValue.group(1));
out.write("\n");
out.close();
Any ideas what's wrong with my code? Thanks :-)

How do you read the code into the bsh interpreter? It sure looks like the double backslashes are reduced to single ones.
As a quick fix, just use forward slashes instead of backslashes, e.g.
FileWriter fstream = new FileWriter("c:/downloads/results.txt",true);

Related

Error when importing sklearn in pipeline component

When I run this simple pipeline (in GCP's Vertex AI Workbench) I get an error:
ModuleNotFoundError: No module named 'sklearn'
Here is my code:
from kfp.v2 import compiler
from kfp.v2.dsl import pipeline, component
from google.cloud import aiplatform
#component(
packages_to_install=["sklearn"],
base_image="python:3.9",
)
def test_sklearn():
import sklearn
#pipeline(
pipeline_root=PIPELINE_ROOT,
name="sklearn-pipeline",
)
def pipeline():
test_sklearn()
compiler.Compiler().compile(pipeline_func=pipeline, package_path="sklearn_pipeline.json")
job = aiplatform.PipelineJob(
display_name=PIPELINE_DISPLAY_NAME,
template_path="sklearn_pipeline.json",
pipeline_root=PIPELINE_ROOT,
location=REGION
)
job.run(service_account=SERVICE_ACCOUNT)
What do I do wrong? :)
It seems that the package name sklearn does not work after a version upgrade.You need to change the value of packages_to_install from "sklearn" to "scikit-learn" in the #component block.

How to get rid of positional argument error while using map function in tensorflow dataset

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import tensorflow as tf
from tensorflow import keras
import tensorflow_datasets as tfds
( ds_train,ds_test),ds_info=tfds.load("mnist",split=['train',"test"],
shuffle_files=True,with_info=True)
def normalize(image,label):
image=tf.cast(image,tf.float32)
return image/255.0,label
AUTOTUNE=tf.data.experimental.AUTOTUNE
new_ds=new_ds=ds_train.map(normalize,num_parallel_calls=AUTOTUNE)
When I execute 'ds_train.map' it shows me Below error:
TypeError: in user code:
TypeError: tf__normalize() missing 1 required positional argument:
'label'

shutil error: "Module 'shutil' has no 'copy' member"

I am still learning python but got stuck here:
from pathlib import Path
import os
import shutil
p = Path.home()
shutil.copy(p / 'G:\souce.txt', p / 'G:\dest.text')
The error is:
shutil: shutil
Anomalous backslash in string: '\s'. String constant might be missing an r prefix.pylint(anomalous-
backslash-in-string)
Anomalous backslash in string: '\d'. String constant might be missing an r prefix.pylint(anomalous-
backslash-in-string)
Module 'shutil' has no 'copy' memberpylint(no-member)
Not able to go for the next step. So any suggestions please.
You can just do:
import shutil
shutil.copy('G:\souce.txt', 'G:\dest.text')

how to remove the unused genreated require when use protobuf anotations

package usegogo.api.v1;
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/field_mask.proto";
import "gogoproto/gogo.proto";
option (gogoproto.marshaler_all) = false;
I use gogoproto to generate go codes.
But when I generate nodejs code, there is a var gogoproto_gogo_pb = require('../../../gogoproto/gogo_pb.js');
this is generated because i use import "gogoproto/gogo.proto";
is there any way to let protoc ignore the the import "gogoproto/gogo.proto"; sine i don't use this when i genreate nodejs code.
Protoc will actually generate gogo_pb.js if you point it to gogo.proto like you do with your other proto files.

Jmeter beanscript get currentTime doesnt work

I am new to Jmeter. create a Jsr223 postprocessor and select language as Bsh.
import java.util.Date;
import java.text.SimpleDateFormat;
long mill = System.currentTimeMillis();
log.info(mill);
output:
ERROR - jmeter.extractor.JSR223PostProcessor: Problem in JSR223 script JSR223 PostProcessor javax.script.ScriptException: Sourced file: inline evaluation of: ``import java.util.Date; import java.text.SimpleDateFormat; long mill = System.c . . . '' : Error in method invocation: Method info( long ) not found in class'org.apache.log.Logger' : at Line: 5 : in file: inline evaluation of: ``import java.util.Date; import java.text.SimpleDateFormat; long mill = System.c . . . '' : log .info ( mill )
in inline evaluation of: ``import java.util.Date; import java.text.SimpleDateFormat; long mill = System.c . . . '' at line number 5
at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:92)
at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:46)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:206)
at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:42)
at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:776)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:489)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
at java.lang.Thread.run(Unknown Source)
please advise a fix. thank you!
First of all, are you aware of __time() JMeter function which can output current time in the different formats?
If you still want to do it in Beanshell be informed that you cannot print a Long value directly to jmeter.log file, you need to cast it to String first using one of the following approaches
log.info(String.valueOf(mill));
log.info(Long.toString(mill));
log.info("Current time is: " + mill);
You can get a "good" Beanshell error by putting your code inside the try block like:

Resources