Python Series Question Set 02-When using the datahub_console client provided by Alibaba Cloud to download datahub data, the specified time point parameters are invalid.

Background: Solution to the problem that the time setting is invalid when the datahub SDK package downloads topic data

Download the datahub console client from the Alibaba Cloud official website. During use, I found that after specifying any time point, I found that the download always starts from the oldest piece of data in the datahub. It is initially suspected that there is a problem with the client package. Client download URL:

https://help.aliyun.com/document_detail/184383.html?spm=a2c4g.11186623.6.585.7e0c642e97pFDC

So, I came up with the idea to directly download the SDK of datahub to write operation and maintenance tools, using python version 2.7.15.

See my other article for the installation process:

https://blog.csdn.net/weixin_40012925/article/details/126317198

After the environment was set up, we started to write the download interface that called the SDK. The result was the same as using the datahub_console client directly. If we specify any time, the longest stored data in the datahub is downloaded, so we analyzed the reasons: 1) The SDK itself does not Supports specifying time offset points, and the parameters are invalid; 2) There is an issue with the usage of the calling interface.

Starting from the parameter time point query, the parameters only support the timestamp format. I found that the python time function converts the time into a timestamp at the second level. There happened to be a timestamp in the data I downloaded that recorded the millisecond level. It felt like changing clothes. This is the reason, so I converted the timestamp to *1000 and then passed the parameters. As a result, a parameter type error was reported. The interface requirement is int type, and the timestamp of the passed parameter is long type.

View the SDK source package and obtain the datahub cursor function information as follows:
Insert image description here

Insert image description here


    @type_assert(object, str, str, str, CursorType, long)
    def get_cursor(self, project_name, topic_name, shard_id, cursor_type, param=-1):

        return self._datahub_impl.get_cursor(project_name, topic_name, shard_id, cursor_type, param)

So I thought about changing the rendering-limited int type to long type, and then reinstalling the SDK package to solve the problem.
Insert image description here

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_40012925/article/details/126317578