Python requests, post multipart/form-data encoded with utf-8 - post

I have the following data that I need to send it in the form of post request to a server that accepts multipart/form-data
data = ( ('key1', (None, 'some_data')),
('key2', (None, ' ™ ™ ™ data contains Unicode characters ™ ™ ™ ')),
)
I'm using python3.7
import requests
requests.post(url, files=data)
The server currently is not recognizing the ™ character.

Related

How to pass the 'function value' in api address of thingSpeak.. I am using Arduino and sim900 GSM

I want to upload rain sensor data to thingspeak using HTTP POST method, But while using "Api key= data to be sent .."
The sensor data is not being uploaded to server.. and also as it is in quotes so it is not taking as function may be....
How to solve this problem??
Serial.print("api_key=QI8G7PVTC2BVIREC&field1=TellWater()\\r\\n");
You need to capture the return value of the TellWater() in a variable.
Here I am assuming TellWater() return float. You need to convert it to string.
float water_value = TellWater();
String water_value_str;
water_value_str = String(f);
After you convert the sensor data to string, you need to perform string concatenation to prepare final output string.
String output_string = "api_key=QI8G7PVTC2BVIREC&field1=" + water_value_str + "\r\n";
Serial.print(output_string);
You should not escape back slash \ in \\r\\n. This will cause compiler to interpret the statement as character \ (0x5c) and character r (0x72) instead as \r (0x0D) (carriage-return). Similarly \\n will be interpreted as character \ (0x5c) and character n (0x6e) instead as \n (0x0A) (line-feed) causing your GSM module to wait for data as it has not received line-ending characters (\r\n).

Karate: Query Param values are getting encoded

I am using karate 0.6.1 version and facing issue with get request with queryparam.
Scenario Outline: Verify the response Data with account details when there are filter values are provided with wildcard
Given params { <paramName>: <paramValue> }
When method get
Then status 200
Examples:
| paramName | paramValue |
| Name | 'Volvo%' |
| Name | 'test data'|
in the request url with queryparam becomes like url?Name=Volvo%25
And url?Name=test+data
which is not correct, how should i resolve that.
It is actually not wrong,
Url encoding is required to differentiate between special characters in your data vs special characters that are reserved to construct the URL.
Reserved Characters URL Encoding:
: Separate protocol (http) from address encoded as %3B
/ Separate domain and directories encoded as %2F
# Separate anchors encoded as %23
? Separate query string encoded as %3F
& Separate query elements encoded as %24
# Separate username and password from domain encoded as %40
% Indicates an encoded character encoded as %25
+ Indicates a space encoded as %2B
<space> Not recommended in URLs encoded as %20 or +
so if you are going to pass any special characters as data via URL you need to % encode them to avoid conflicts.
In karate, if you want to avoid your URL getting encoded, don't construct your URL using path, params, param definitions.
Instead, build your entire URL as a string and pass it to url. like,
* url 'http://httpbin.org/get?Name=Stark'
You might get an exception if you are trying to pass any special
characters in this.
so consider encoding the URL if you are going to pass any special characters.

Rails encode control characters and send over a socket

Using Eventmachine I have been able to build a simple client/server program that successfully sends data over a socket. But the server expects that data is a specific format.
In order to communicate with the server, the first step is to send a WAKEUP call and get acknowledgment. The server expects a 3 byte ID in the wakeup call. An example is provided in the documentation that shows the success scenario of sending the ID and receiving the ack.
The client should send the data is the following format:
<sy><sy><eq>111<et>
Within <> brackets is a non-printable ASCII character ( <sy> = ASCII 22 or Hex 0x16)
Here is some detail of the characters:
<sy> = ASCII: 22, Hex: 0x16 , Character: ^V
<eq> = ASCII: 5, Hex: 0x05 , Character: ^E
<et> = ASCII: 4, Hex: 0x04 , Character: ^D
I'm using a gem Bindata to represent the <sy><sy><eq>111<et> but don't know exactly which type to use. Can you provide a way to acheive this?

Cannot find base64 encoded string

I have a MS Doc file and I have converted it from Blob to Base64 encoded string. It contains a string in it as: <z></z>
And I have base64 encoded string for this: <z></z>
But when I search it in the above string converted from blob data then I am not able to find it!!
Can you guide me what I am doing wrong:
Blob beforeblob1 = Blob.valueOf(vDovMerge.Merge_Text__c);
String vDovMergeBlob = EncodingUtil.base64Encode(beforeblob1 );
String v = EncodingUtil.base64Encode(vDoc.Body);
system.debug('****v****'+v);
Blob beforeblob = Blob.valueOf('<z></z>');
String rep = EncodingUtil.base64Encode(beforeblob );
system.debug('****rep****'+rep );
v = v.replace(rep ,vDovMergeBlob );
system.debug('****v****'+v);
Base64-encoding converts 3 bytes of input to 4 bytes of output. So when encoding <z></z> only it is sure to start as the first byte of the block to be encoded. When encoding it as part of a larger data-block it may end up starting as the second or third byte to be encoded thus producing totally different output - that even depends on the data surrounding your block.
Example:
Assuming ASCII-encoding
encoding <z></z> results in PHo+PC96Pg==
encoding a<z></z>results in YTx6Pjwvej4=
encoding aa<z></z> results in YWE8ej48L3o+
encoding aaa<z></z> results in YWFhPHo+PC96Pg== which again contains the original encoding since it starts on a 3-byte-boundary.
So the only way to search the base64-encoded data would be to treat it as a bit-stream and search for the bit-pattern of <z></z> without respect to byte-boundaries - doesn't sound like a lot of fun to me :-(

percent encoding - how is a greek letter percent encoded?

I'm browsing the web for a answer but cannot find one. I have a HTML form (method=GET) and submit in a text field the text helloΩ (hello with the greek letter Omega appended)
The URL in the browser encodes it as:
mytext=hello%26%23937%3B
Without the greek letter Omega appended, I get (as expected):
mytext=hello
So how is the greek Omega letter percent encoded into:
%26%23937%3B
Thanks
This happens when your web server declared an encoding that doesn't support the character. For example, ISO-8859-1 doesn't support it which is the default encoding for many web servers.
That's a html entity character reference percent-encoded: Ω, because #, & .. are all ASCII characters, this is the only way to not lose information because the browser thinks the server only supports ISO-8859-1.
To fix this, declare UTF-8 in your http header:
Content-Type: text/html; charset=utf-8
This isn't even consistent behavior between browsers, because IE encodes it as hello%D9, which is Ú in CP1252/ISO-8859-1.

Resources