Git Product home page Git Product logo

oapi-sdk-python's People

Contributors

keeperlibofan avatar maemual avatar maowenbo666 avatar vxenomac avatar zhailuxubyte avatar zhaoche27 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

oapi-sdk-python's Issues

Protobuf error at python 3.11

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:

  1. Downgrade the protobuf package to 3.20.x or lower.
  2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

Response does not close after use

self.resp = resp
if self.req.is_response_stream_current:
if self.req.response_stream_file:
for buffer in self.req.response.iter_content(chunk_size=2048):
self.req.response_stream_file.write(buffer)
resp.data = self.req.response_stream_file
else:
resp.data = self.req.response.content
self.req.response.close()
return
resp_json = self.req.response.json()
self.config.logger.debug("request http_path:%s, response status code:%d, response body:%s" % (
self.req.http_path, self.req.response.status_code, resp_json))
if isinstance(resp_json, dict):
resp.code = resp_json.get('code')
resp.msg = resp_json.get('msg')
resp.error = make_datatype(ResponseError, resp_json.get('error'))
if self.req.no_data_field:
resp.data = make_datatype(self.req.output_class, resp_json)
else:

As above, there should have a corresponding close call at

resp_json = self.req.response.json()
.

This bug would cause exception if we have many requests in a short range of time.

im.message.message_read_v1 订阅消息已读事件报错

err: processor not found, type: im.message.message_read_v1
Traceback (most recent call last):
  File "/home/.../lark_oapi/event/dispatcher_handler.py", line 83, in do
    raise EventException(f"processor not found, type: {context.type}")
lark_oapi.core.exception.EventException: processor not found, type: im.message.message_read_v1

im.message.message_read_v1 这个订阅消息已读事件报错报错。是不是SDK里没有拓展这个processor?

更新:不好意思,找到了。

larksuiteoapi.api.Request 不支持服务台API的token

飞书服务台API要求在HTTP请求头中加入X-Lark-Helpdesk-Authorization字段。

请求中代入服务台token,表示拥有和服务台负责人相同的权限(查看修改服务台实体)。
使用方法,设置在请求Header中:

  • Header Key: X-Lark-Helpdesk-Authorization
  • Header Value: base64(helpdesk_id:helpdesk_token), 通过base64加密将helpdesk_id和helpdesk_token用':'连接而成的字符串。

目前SDK中的larksuiteoapi.api.Request没有自定义header的选项。若调用服务台API,需要直接修改存在larksuiteoapi.api.Request.sessionrequests.Session对象的headers,暴露了其实现细节。

建议SDK在后续添加服务台API服务的支持,并优化Request对象的接口。

Add wiki support

Currently it's hard to analysis wikis on Lark app, if there are some wiki APIs then developers can give out some analytics tools for wiki.

sheet 追加数据 报forbidden

req = Request('sheets/v2/spreadsheets/:spreadsheetToken/values_append','POST', ACCESS_TOKEN_TYPE_TENANT, valueRange,
request_opts=[set_path_params(path_params),set_query_params(query_params)])


{'code': 91403, 'data': {}, 'msg': 'Forbidden'}

在文档中https://open.feishu.cn/document/ukTMukTMukTM/ugjM14COyUjL4ITN 的错误描述是

91403 | FORBIDDEN | 没有权限 | 检查是否有文档读权限

我尝试读取sheet是可以读到的,但 写入 不成功。请大神指导

Object of type ConnectionError is not JSON serializable

def do_request(self, config): # type: (Config) -> requests.Response

感觉当 session.request 报错 TimeoutError 的时候,返回的 response json序列化出了问题。

我在最外层调用,比如:

req = Request(oapi_path, http_method, ACCESS_TOKEN_TYPE_TENANT, request_body=request_body, request_opts=request_opts)

try:
  res = req.do(self.config)
exception Exception as e:
  logging.error(e)

这块捕捉到了 'Object of type ConnectionError is not JSON serializable' 这个错误。

获取飞书表格数据报错

执行 .set_range("XXXX!A1:C10") 的时候报错。报错内容:AttributeError: '_SpecialForm' object has no attribute 'args'

larksuiteoapi/logger.py:48 logger:error ERROR- err occurred, 'utf-8' codec can't decode byte 0xb8 in position 0: invalid start byte

环境:
python3.8.16/3.10/3/11
django4.2
larksuite-oapi 1.0.33/1.0.34

问题

# 使用消息接收回调事件时,code部分如下
MessageReceiveEventHandler.set_callback(dd.conf, rec_msg_handle)
class FS(View):
  ......
  def post(self, req):
    oapi_request = OapiRequest(uri=req.path, body=req.body, header=OapiHeader(req.headers))
    handle_event(conf, oapi_request)
    .......
报错如下
/home/app/pls_env_with_python38/lib/python3.8/site-packages/larksuiteoapi/logger.py:48 logger:error ERROR- err occurred, 'utf-8' codec can't decode byte 0xb8 in position 0: invalid start byte
ERROR:root:err occurred, 'utf-8' codec can't decode byte 0xe0 in position 3: invalid continuation byte

但是使用同样的sdk,给指定的user_id发消息是OK的

RefreshAccessToken got invalid request

Error Message: client.authen.v1.refresh_access_token.create failed, code: 20001, msg: invalid request, grant_type should be authorization_code or refresh_token,
The grant_type is already set to 'refresh_token', same refresh_token works on pure curl request.

request: CreateRefreshAccessTokenRequest = CreateRefreshAccessTokenRequest.builder()
.request_body(CreateRefreshAccessTokenRequestBody.builder()
.grant_type("refresh_token")
.refresh_token("xxxxx")
.build())
.build()

SDK业务API地址在Windows环境错误

问题描述

Windows环境下调用SDK业务时API URL拼接错误,提示 resource not find

环境

Windows 10 Python 3.8.8

示例

from larksuiteoapi.service.contact.v3 import Service as ContactV3Service, User

from larksuiteoapi import Config, DOMAIN_FEISHU, DefaultLogger, LEVEL_DEBUG

app_settings = Config.new_internal_app_settings("AppID", "AppSecret", "VerificationToken", "EncryptKey")
from src.larksuiteoapi.service.contact.v3 import User

app_settings = Config.new_internal_app_settings_from_env()
conf = Config.new_config_with_memory_store(DOMAIN_FEISHU, app_settings, DefaultLogger(), LEVEL_DEBUG)

service = ContactV3Service(conf)
user = User()

service.users.get(user).do()
DEBUG: request http_path:https://open.feishu.cn/open-apis/contact/v3\users/, http_method:GET, access_token_type:tenant_access_token, request body:b''
DEBUG: Starting new HTTPS connection (1): open.feishu.cn:443
DEBUG: https://open.feishu.cn:443 "GET /open-apis/contact/v3%5Cusers/ HTTP/1.1" 404 43
DEBUG: request http_path:https://open.feishu.cn/open-apis/contact/v3\users/, response status code:404, response body:{'code': 99991201, 'msg': 'resource not find'}

建议


http_path = path.join(root_service.base_path, 'departments/:department_id')

注意到SDK中使用了os.path.join来拼接URL,但在Windows环境下会默认使用\作为分隔符。
建议使用 urllib.parse.urljoin (python2 中为 urlparse.urljoin

PHP SDK

会有PHP SDK包吗?如果有的话,会在什么时候上线?

create group property missing

In im/v1/model/ChatCreateReqBody, field user_id_list is missing, which causes no user in new group after created.

SDK难以支持异步框架

目前SDK中的API client接口固定使用requests,事件处理接口也定为使用回调函数,难以配合基于asyncio的异步web框架使用(如StarletteFastAPI)。
能否考虑添加基于asyncio的异步支持?或者将核心逻辑部分剥离出来,封装为非阻塞的组件(类似h2)呢?

获取多维表格错误:

获取多维表格错误:
python2.7.11

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\liudongdong.dd\AppData\Roaming\Python\Python27\site-packages\larksuiteoapi\service\bitable\v1\api.py", line 1057, in do
resp = req.do(conf)
File "C:\Users\liudongdong.dd\AppData\Roaming\Python\Python27\site-packages\larksuiteoapi\api\request\request.py", line 175, in do
return Handlers(conf, self).handle()
File "C:\Users\liudongdong.dd\AppData\Roaming\Python\Python27\site-packages\larksuiteoapi\api\request\request.py", line 333, in handle
raise e
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 35: ordinal not in range(128)

s0YyypjryU

Transport cannot deal with utf-8 request body

D:\repos\oapi-sdk-python> & C:/Users/xm/AppData/Local/Programs/Python/Python310/python.exe d:/repos/oapi-sdk-python/test.py
[Lark] [2023-07-26 11:57:45,031] [DEBUG] POST https://xxxxx//open-apis/auth/v3/tenant_access_token/internal 200, headers: {"User-Agent": "oapi-sdk-python/v1.0.0"}, params: [], body: {"app_id": "xxx", "app_secret": "xxx", "app_ticket": null, "app_access_token": null, "tenant_key": null}
Traceback (most recent call last):
File "d:\repos\oapi-sdk-python\test.py", line 64, in
test_create_record({"ReleaseLink":{"text":'sss',"link":'www.baidu.com'},"发布日期":datetime.datetime.now().astimezone().isoformat(),"Changelog":'aaaa',"描述":'tagMsg',"发布版本":'tagThis',"项目
配置":'ssss'},"tbllCztYEz7Drn4A")
File "d:\repos\oapi-sdk-python\test.py", line 51, in test_create_record
response: CreateAppTableRecordResponse = client.bitable.v1.app_table_record.create(request)
File "d:\repos\oapi-sdk-python\lark_oapi\api\bitable\v1\resource\app_table_record.py", line 95, in create
resp: RawResponse = Transport.execute(self.config, request, option)
File "d:\repos\oapi-sdk-python\lark_oapi\core\http\transport.py", line 26, in execute
response = requests.request(
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1327, in _send_request
body = _encode(body, 'body')
File "C:\Users\xm\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 166, in _encode
raise UnicodeEncodeError(
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 185-188: Body ('发布日期')
is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

[feature request] Add some Enum types

I'm using docx.v1.ListDocumentBlockRequest to get a docx.v1.Block. Then I'd like to write:

def get_text_block_by_type(block: docx.v1.Block) -> docx.v1.Text:
    name = FeishuBlockType(block.block_type).name
    value = block.__getattribute__(name)
    if isinstance(value, docx.v1.Text):
        return value
    else:
        return None

class FeishuBlockType(Enum):
    page = 1
    text = 2
    heading1 = 3
    heading2 = 4
    heading3 = 5
    heading4 = 6
    heading5 = 7
    heading6 = 8
    heading7 = 9
    heading8 = 10
    heading9 = 11
    bullet = 12
    ordered = 13
    code = 14
    quote = 15
    equation = 16
    todo = 17
    bitable = 18
    callout = 19
    chat_card = 20
    uml_diagram = 21
    divider = 22
    file = 23
    grid = 24
    grid_column = 25
    iframe = 26
    image = 27
    isv = 28
    mindnote = 29
    sheet = 30
    table = 31
    table_cell = 32
    view = 33
    quote_container = 34
    task = 35
    okr = 36
    okr_objective = 37
    okr_key_result = 38
    okr_progress = 39
    add_ons = 40
    jira_issue = 41
    wiki_catalog = 42

I belive it will be useful for developers to have the Enum types in lark_oapi , perticularly the fields like:

image
image
image

Relate to https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/list

Server Error

在使用lark_sdk.get_sheets的时候,会报错Server_error,请问这样的问题如何解决?非常感谢!
VAXhv8zuWd

User token 获取

README 中提到了可以构建request 获得 user_token, 是否指根据这个方法构建request, 然后parse结果获取?

但是关于 request.SetUserAccessToken("user_access_token") 这句话的使用地方没有找到, 想问问这句话是什么意思.

谢谢

请将"读取多个范围"api中 valueRange改为valueRanges

问题描述

使用此API时Reading multiple ranges返回的body中“值与范围”为None。
SpreadsheetsValuesBatchGetResult(revision=1, spreadsheet_token='sheet_token', total_cells=160,value_range=None)

解决方法

参考文档“值与范围”对应的键的名称为valueRanges需要将678行的valueRange改为valueRanges。

value_range = attr.ib(type=List[ValueRange], default=None, metadata={'json': 'valueRange'})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.