How do I msgpack the below parameters to send in a CURL? - python

device_id={UNIQUE_ID}&key={CUSTOMER_KEY}
I have tried following as many examples as I could find online, but there really wasn't a lot that was helpful for me. I'm using Python and have imported the msgpack and did this:
msgpack.packb([device_id:00000000-0000-0000-0000-000000000000,customer_key:0123456789abcdef])
But I get an error it's invalid syntax, with the colon indicated as the offending character. I wanted to out the msgpack code into a CURL and send it. But so far, I'm doing something wrong in how I define my key/values here.

Related

How to use elasticsearch 8.x ingest-attachment with Python

I am trying to read a pdf from python and send it to elasticsearch.
I tried to use ingest-attachment to help with that, but I don't know how.
https://www.elastic.co/guide/en/elasticsearch/reference/master/attachment.html
When I followed the official documentation, it worked. However, there doesn't seem to be a way to use Python in the official documentation.
so, I looked at the official documentation and created my own mapping
Data is entered but not attached.
Wandered around and found this.
but i don't know how to use
elasticsearch.exceptions.RequestError: RequestError(400, 'invalid_index_name_exception', 'Invalid index name [_ingest/pipeline/attachment_pipeline], must not contain the following characters ['\','/','*
','?','"','<','>','|',' ',',']')
If you just run it, it will come out like this: It looks like you have / in your index name. So this time I only ran the bottom part.
elasticsearch.exceptions.RequestError: RequestError(400, 'illegal_argument_exception', 'pipeline with id [attachment_pipeline] does not exist')
..........
I want to know how to use it..
How to make attachment plugin work in python

How to post json file with pydruid?

I went through pydruid documentation docs and could not find a single example where I can use the existing JSON file to convert it into a format which pydruid can use to post(start the job). We are using older version of druid so we may not have all the latest functionalities. I'm sure I might be able to achieve the same behavior with pycurl but somehow feel pydruid is a better approach here. Can someone post an example of how I can use the exiting JSON file with prdruid?

I cannot calculate a working AWS signature version 4 (hexadecimal string) for curl commands to work to test the REST API

I have never been able to get Rest APIs to completely work with AWS. The error messages I have seen have been about the time not being correct or the command not being recognized (e.g., list-users). I have verified the "version" was appropriate for the command with AWS's website documentation.
I am trying to use curl with Linux to list the users or instances in my AWS account. I have a problem when I run it. My current error, that I would like to focus on, is "request signatures calculated does not match the signature provided." I went through the process of creating a signature carefully. It wasn't that surprising that it did not work given the hours of trouble and the seemingly many potential pitfalls in the tedious task of creating a signature.
I used this link to generate the hexadecimal string for the signature:
http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-python
I analyzed the output of the signatureKey using a modification of the Python code in the above link. The result is not hexadecimal nor alphanumeric. The result is a combination of special non-alphabet, non-numeric symbols and alphabet letters. I tried to work around this problem by using import binascii and binascii.hexlify. I was able to get a hexadecimal string from otherwise strictly adhering to the sample of Python code from the above link. I tend to think my signatureKey is not right because of this binascii work that I had to do. But what did I do wrong? How is that Python code supposed to calculate a signature?
Alternatively, are there thorough directions not written by Amazon to create a signature key? The process is not simple and seemingly error prone. I could start over with creating a signature if someone cannot clearly tell me how to create a signature. Amazon's forums have few postings related to this topic. I'd prefer to create the signature with Python. If someone recommends Ruby (an accessible language for me), I could try something like that.

Decoding problems in Django and lxml

I have a strange problem with lxml when using the deployed version of my Django application. I use lxml to parse another HTML page which I fetch from my server. This works perfectly well on my development server on my own computer, but for some reason it gives me UnicodeDecodeError on the server.
('utf8', "\x85why hello there!", 0, 1, 'unexpected code byte')
I have made sure that Apache (with mod_python) runs with LANG='en_US.UTF-8'.
I've tried googling for this problem and tried different approaches to decoding the string correctly, but I can't figure it out.
In your answer, you may assume that my string is called hello or something.
"\x85why hello there!" is not a utf-8 encoded string. You should try decoding the webpage before passing it to lxml. Check what encoding it uses by looking at the http headers when you fetch the page maybe you find the problem there.
Doesn't syntax such as u"\x85why hello there!" help?
You may find the following resources from the official Python documentation helpful:
Python introduction, Unicode Strings
Sequence Types — str, unicode, list, tuple, buffer, xrange
Since modifying site.py is not an ideal solution try this at the start of your program:
import sys
reload(sys)
sys.setdefaultencoding("utf-8")

Decoding a WBXML SyncML message from an S60 device

I'm trying to decode a WBXML encoded SyncML message from a Nokia N95.
My first attempt was to use the python pywbxml module which wraps calls to libwbxml. Decoding the message with this gave a lot of <unknown> tags and a big chunk of binary within a <Collection> tag. I tried running the contents of the <Collection> through by itself but it failed. Is there something I'm missing?
Also, does anyone know of a pure python implementation of a wbxml parser? Failing that a command line or online tool to decode these messages would be useful -- it would make it a lot easier for me to write my own...
Funnily enough I've been working on the same problem. I'm about halfway through writing my own pure-Python WBXML parser, but it's not yet complete enough to be useful, and I have very little time to work on it right now.
Those <Unknown> tags might be because pywbxml / libwbxml doesn't have the right tag vocabulary loaded. WBXML represents tags by an index number to avoid transmitting the same tag name hundreds of times, and the table that maps index numbers to tag names has to be supplied separately from the WBXML document itself. From a vague glance at the libwbxml source it seems like libwbxml has a bunch of tag tables hard coded. It has tables for SyncML 1.0-1.2; I think my Nokia E71 sends SyncML 1.3 (if so, your N95 probably does too), which it looks like libwbxml doesn't support yet.
Getting it to work might be as simple as adding a SyncML 1.3 table to libwbxml. That said, last time I tried, pywbxml doesn't compile against the vanilla libwbxml source, so you have to apply some patches first... so "simple" may be a relative term.
I ended up writing a python parser myself. I managed to do it by following the spec here:
http://www.w3.org/TR/wbxml/
And then taking the code tables from the horde.org cvs.
The open mobile alliance's site and documentation are terrible, this was a very trying project :(
I used pywbxml ,
Just needed one patch in pywbxml.pyx:
params.lang in function wbxml2xml around line 25 set to:
params.lang = WBXML_LANG_UNKNOWN
works like charm. Also changing base class for WBXMLParseError to exception helps:
class WBXMLParseError(Exception):

Categories

Resources