larksuite / oapi-sdk-python Goto Github PK
View Code? Open in Web Editor NEWLarksuite development interface SDK
License: MIT License
Larksuite development interface SDK
License: MIT License
samples/api/auth/v3/internal_app_access_token_sample.py
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
AttributeError: 'InternalAppAccessTokenResponse' object has no attribute 'data'
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:
More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
大佬有没有交流群
SDK目前仅封装了用于H5 app的access token接口,而缺少用于与小程序交互的code2session接口,希望能够添加。
oapi-sdk-python/src/larksuiteoapi/api/request/request.py
Lines 280 to 300 in 4274991
As above, there should have a corresponding close call at
.This bug would cause exception if we have many requests in a short range of time.
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?
更新:不好意思,找到了。
调用 https://open.larksuite.com/document/ukTMukTMukTM/uMDO1YjLzgTN24yM4UjN 这个接口时返回2200,Internal Error None,请问怎么样解决呢?
飞书服务台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.session
的requests.Session
对象的headers
,暴露了其实现细节。
建议SDK在后续添加服务台API服务的支持,并优化Request对象的接口。
如果想有很多不同的消息卡片,如何区分它们呢?
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.
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是可以读到的,但 写入 不成功。请大神指导
报错:AttributeError: module 'lark_oapi' has no attribute 'ws'. Did you mean: 'os'?
代码为示例代码:
https://github.com/larksuite/oapi-sdk-python/blob/v2_main/samples/ws/sample.py
感觉当 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'
oapi-sdk-python/src/larksuiteoapi/config.py
Lines 45 to 46 in b514d80
if app_secret == '':
raise RuntimeError('environment variables not exist `APP_SECRET`')
环境:
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
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()
values_batch_get
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'}
注意到SDK中使用了os.path.join
来拼接URL,但在Windows环境下会默认使用\
作为分隔符。
建议使用 urllib.parse.urljoin
(python2 中为 urlparse.urljoin
)
当用户输入触发消息卡片发送时,消息卡片会发送多次,请问怎么解决呢?
会有PHP SDK包吗?如果有的话,会在什么时候上线?
就是我想使用user access token,现在不知道怎么获取到授权码
lark bot api其中的一个function不太稳定,最近操作lark sheet添加或者删除新tab的时候总是无法成功,之前没出现过这种问题;是不是最近的service有问题img_v2_001a6b09-73e1-4517-ba11-0cd4a64bfcah
expire 是离过期还有多少秒,是一个时间段,time.time()获得的是当前的绝对时间,两者不能进行比较
In im/v1/model/ChatCreateReqBody
, field user_id_list
is missing, which causes no user in new group after created.
在使用im.v1.message_resource的get方法获取资源文件时,提示AttributeError: 'RawResponse' object has no attribute 'header'。
https://open.feishu.cn/document/server-docs/docs/bitable-v1/app-table-record/list
Demo里示例
.filter("AND(CurrentValue.[身高]>180, CurrentValue.[体重]>150)")
但是完全没有可参考性. 我不知道这个fields都有哪些.
"fields": {
"created_at": 1704206701000,
"created_date": [
{
"text": "2024/01/02",
"type": "text"
}
],
...
}
以上述fields为例, 我需要过滤 created_date等于2024/01/02, 要如何写这个filter?
I guess this line of code should be AccessTokenType.USER since there is not a method to get user_access_token
Also I hope there can be a method to find user_access_token
Relate to #54
如果用django来替代flask应该怎么实现?
原本larksuite-oapi(main分支)不维护了吗?
包名都要改的话,建议在v2 main分支的readme加个说明
获取多维表格错误:
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)
larksuiteoapi.service下这些服务,文档在哪里呀?现在只能一点点看源码,效率太低了。
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.
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:
Relate to https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/list
README 中提到了可以构建request 获得 user_token, 是否指根据这个方法构建request, 然后parse结果获取?
但是关于 request.SetUserAccessToken("user_access_token")
这句话的使用地方没有找到, 想问问这句话是什么意思.
谢谢
根据最新的文档,这里应该有一个message_id,否则无法更新卡片消息
使用此API时Reading multiple ranges返回的body中“值与范围”为None。
SpreadsheetsValuesBatchGetResult(revision=1, spreadsheet_token='sheet_token', total_cells=160,value_range=None)
参考文档“值与范围”对应的键的名称为valueRanges需要将678行的valueRange改为valueRanges。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.