percent encode out of range exception - arrays

I have a problem with percent.encode() in package:convert/convert.dart package.
I have an API that is used by the Arabs and can contain Arabic characters. One of the Arabic characters is "خ" and if I want to convert it with this method percent.encode('خ'.codeUnits). The code unit number is 1582 which represents 0x62e in hexadecimal. In this case, I will get an exception because it's out of range of the bytes that this library can convert. and I have this exception Unhandled Exception: FormatException: Invalid byte 0x62. Can you please help me with my problem? are there any alternatives I can use?

I have found a solution, I've used Uri.encodeQueryComponent(data). It did the trick.
[Update 1]
There is an alternative way
percent.encode(utf8.encode('خ'))

Related

one-hot encoding issue

I have the following code which i am trying to achieve one hot encoding.
k=tf.Variable(tf.zeros((10,1)))
hprev=tf.Variable(tf.zeros((10,1)))
x=tf.placeholder(tf.int32,shape=None,name="x")
y_op =tf.assign(k, k[x,0].assign(1))
M_c=tf.concat((hprev,y_op),axis=0)
init=tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(y_op,feed_dict={x:1}))
print(M_c.eval())
I get the error:You must feed a value for placeholder tensor 'x_64' with dtype int32. Yet I have passed 1 as the value, which in my understanding is an integer. What I am doing wrong ?. I am still a beginner please.

ColdFusion server file with apostrophe character

When I try to upload a file with apostrophe, I get the error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
if the file name is test's.pdf, I get the error. But if I change the name to test.pdf, there is no error.
Does anyone know why?
Thanks
I had a similar situation where I was dynamically creating filenames for pages that created excel files from query results. The approach I took was to create a function that replaced all the bad characters with something. Here is part of that function.
<cfargument name="replacementString" required="no" default=" ">
<cfscript>
var inValidFileNameCharacters = "[/\\*'?[\]:><""|]";
return reReplace (arguments.fileNameIn, inValidFileNameCharacters, arguments.replacementString, "all");
</cfscript>
You might want to consider an opposite approach. Instead of declaring invalid characters and replacing them, declare valid ones and replace anything that is not in the list of valid characters.
I suggest making this a function that's available on all appropriate pages. How you do that depends on your situation.
My guess is that the apostrophe is one of those multi-character apostrophes that Microsoft Word often uses. A character like that may not be a valid character for your OS file system.
You may want to re-code the system to use a temporary file on upload and then rename it to a valid file name after the upload is successful.
Here's some basic trouble shooting info.
Wrap your code in a try/catch block and dump the full error to the page output. Examples of using try/catch/dump below. The examples below force an error by dividing by zero.
For tag based cfml:
<cftry>
<cfset offendingCode = 1 / 0>
<cfcatch type="any">
<cfdump var="#cfcatch#" label="cfcatch">
</cfcatch>
</cftry>
For cfscript cfml:
<cfscript>
try {
offendingCode = 1 / 0;
} catch (any e) {
writeDump(var=e, label="Exception");
}
</cfscript>

Error in sort.list(y) : invalid input 'Eldon Imàge® Series Desk Accessories, Clear' in 'utf8towcs'

I'm still a newbie in R and I have ran logistic regression model with the below code and the error in the title appeared.Please help
code
logit_model <- glm(train_data$Returns ~ .,
data=train_data,
family =binomial (link="logit"))
No worries fam,the error was that one of the columns had a long name in it.Logistic regression could not execute,maybe it was length issue
The error is related to encoding, check this word "Imàge®", it has Unicode characters.

Altova Mapforce- Could not find start of message error

I am using Altomava Mapforce to map and load 837 x12 formatted text files directly to Sql Server 2014. I have correctly mapped everything except I get the following errors-
Missing field F142- Application Senders code
Could not find start of message with impl.convention reference '116731H333B2'. Message will be skipped.
Missing segment GE
I have included my header and footer information below from the original source text file. Does anyone know what is going on with the mapping, or if maybe there is something wrong with the data itself? Any help would be greatly appreciated.
Header-
ISA*11* *11* *PP* *ZZ*20121143 *273041*0109*^*00501*000000000*0*T*:~GS*HC**211231153*20141121*1115*01*Y*116731H333B2~ST*837*2000001*116731H333B2~BHT*0029*00*0003000005*20141121*1115*CH
Message Data etc.......
Footer-
~SE*769*2000001~GE*1*01~IEA*1*000000000~
Your data is wrong. Here is a cleaned up version of the ISA / GS. For readability, I put a CR/LF after the segment terminator (~). Please note the ISA and GS do not indicate sender, which is going to cause all kinds of problems for auditing. See my comment above for analysis on the data per your bullet points.
ISA*11* *11* *PP*SENDER *ZZ*20121143 *273041*0109*^*00501*000000000*0*T*:~
GS*HC*SENDER*211231153*20141121*1115*01*X*005010~
ST*837*2000001*116731H333B2~
BHT*0029*00*0003000005*20141121*1115*CH
An example of the enveloping:
ISA*00* *00* *ZZ*Test1Saver *ZZ*RECEIVER *151222*1932*U*00501*000111884*0*P*:~GS*HC*Test1Saver*RECEIVER*20151222*1932*1*X*005010~ST*850*0001~
...
~SE*8*0001~GE*1*1~IEA*1*000111884~
If, 123456789 have value then map 123456789 and if having null or blank or no value then send default 123.
enter image description here

Convert a map to a JSON stringt

I will like to convert a map to a valid JSONOBject or json string. I tried Result.fromContent(map).toString() which seems to work only if map is a valid Hashtable ( no null values). Is there another way?
This is the NPE I get
java.lang.NullPointerException
at com.codename1.processing.PrettyPrinter.toString(PrettyPrinter.java:178)
at com.codename1.processing.PrettyPrinter.print(PrettyPrinter.java:69)
at com.codename1.processing.PrettyPrinter.print(PrettyPrinter.java:60)
at com.codename1.processing.MapContent.toString(HashtableContent.java:113)
at com.codename1.processing.Result.toString(Result.java:314)
at userclasses.StateMachine.onEditorSave(StateMachine.java:284)
at generated.StateMachineBase.processCommand(StateMachineBase.java:257)
at com.codename1.ui.util.UIBuilder.processCommandImpl(UIBuilder.java:1634)
at com.codename1.ui.util.UIBuilder.access$100(UIBuilder.java:85)
at com.codename1.ui.util.UIBuilder$FormListener.actionPerformed(UIBuilder.java:2757)
at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:345)
at com.codename1.ui.Form.actionCommandImplNoRecurseComponent(Form.java:1337)
at com.codename1.ui.Button.fireActionEvent(Button.java:389)
at com.codename1.ui.Button.released(Button.java:424)
at com.codename1.ui.Button.pointerReleased(Button.java:512)
at com.codename1.ui.Form.pointerReleased(Form.java:2353)
at com.codename1.ui.Form.pointerReleased(Form.java:2286)
at com.codename1.ui.Component.pointerReleased(Component.java:2459)
at com.codename1.ui.Display.handleEvent(Display.java:1892)
at com.codename1.ui.Display.edtLoopImpl(Display.java:994)
at com.codename1.ui.Display.mainEDTLoop(Display.java:925)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
The code:
Result.fromContent(map).toString()
Works for Hashtable/HashMap semantics where null values aren't present so they are ignored. If you just want the null values to not appear you can just convert the Map to a HashMap which won't include null values.
If you are getting an exception I suggest posting the stack trace as part of the question and we might be able to fix that.

Resources