GithubHelp home page GithubHelp logo

emo-platform-api-python's People

Contributors

ecpplus avatar keitaito123 avatar siwa1989 avatar suke3kaku3 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

emo-platform-api-python's Issues

Exceptionを扱いやすくする

情報を増やす

  • 理想的にはrequests/aiohttpのエラー内容を共通化して確認できるとデバッグがしやすそう
  • ミニマムだとrequests, aiohttpのエラーをメンバーに持っておく等
  • イメージ
try:
    cilent.some_request() # ここで送っているリクエストの内容が後から見れない
except EmoError as e:
    print("error: ", e)
    print("request:", e.request) # 送ったリクエストの内容
    print("code:", e.code)

階層構造の見直し

  • EmoPlatformError
    • EmoHttpError(code, request, response)
      • RateLimitError
      • etc...
    • NoRoomError
    • NoRefreshTokenError

例外の連鎖をさせないようにする

  • 自動でaccess tokenを更新した処理をしたのちに、エラーが出た際に、更新したときに認証エラーも一緒に表示されないようにする
    • #16 が少し関連

案) トークン保存ファイルについて

現状

  • 初期値はOS環境レベルで指定が必要
  • トークンが固定のファイルに保存される
  • トークンアップデートが必要場合は自動で行って、ファイルに保存する

懸念点

  • トークンがライブラリーに紐付いてるので
    • インスタンスを増やして同時に複数のアカウントを使えない
    • 別々のプログラムから別々のアカウントを使えない(pipenvとかを使わない場合)
  • ユーザーがトークンの保存場所をコントロール出来ない

  • トークンの初期値をClientの __init__ で渡せるようにする
  • トークンの保存場所をClientの __init__ で渡せるようにする(個人的に ii. が良さそう)
    1. 保存用のファイルパスを渡す
      or
    2. トークンアップデート時用のcallbackを渡す(callbackのパラリンピックは新トークン)、保存自体は開発者に任せる

Syncでファイル系を送る時に ValueError: Data must not be a string.

Traceback

Traceback (most recent call last):
  File "cmdline.py", line 140, in <module>
    d = room.send_audio_msg(file_path)
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/api.py", line 289, in send_audio_msg
    return self.base_client._post(
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/api.py", line 151, in _post
    return self._check_http_error(request, update_tokens=update_tokens)
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/api.py", line 116, in _check_http_error
    response = request()
  File "/home/seb/.local/share/virtualenvs/test-env-NjLHGyVC/lib/python3.8/site-packages/requests/api.py", line 117, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/seb/.local/share/virtualenvs/test-env-NjLHGyVC/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/seb/.local/share/virtualenvs/test-env-NjLHGyVC/lib/python3.8/site-packages/requests/sessions.py", line 528, in request
    prep = self.prepare_request(req)
  File "/home/seb/.local/share/virtualenvs/test-env-NjLHGyVC/lib/python3.8/site-packages/requests/sessions.py", line 456, in prepare_request
    p.prepare(
  File "/home/seb/.local/share/virtualenvs/test-env-NjLHGyVC/lib/python3.8/site-packages/requests/models.py", line 319, in prepare
    self.prepare_body(data, files, json)
  File "/home/seb/.local/share/virtualenvs/test-env-NjLHGyVC/lib/python3.8/site-packages/requests/models.py", line 512, in prepare_body
    (body, content_type) = self._encode_files(files, data)
  File "/home/seb/.local/share/virtualenvs/test-env-NjLHGyVC/lib/python3.8/site-packages/requests/models.py", line 122, in _encode_files
    raise ValueError("Data must not be a string.")
ValueError: Data must not be a string.

Client._postdata をstrからdictに変更すると直しますが、これは別の影響があるか分からないので確認お願いします。

環境変数の優先度上げる

  • json優先方式だと、アカウントを切り替えたいときに環境変数の操作だけでは、切り替えることができなくなっている

  • フロー

  1. env access token参照
  2. env refresh token参照 / 更新
  3. json access token参照
  4. json refresh token参照 / 更新
  • testコードも変える必要あるかも

Audio msgの送信の時トークンリフレッシュが行う(?)と再送信が失敗する

再現は今の所1回だけです。
確定ではないですが、Audio file送信の時トークンリフレッシュが行ったことにみえて、以下のエラーが起きました。
すぐ後に同じコードを実行したら成功しました。

Traceback (most recent call last):
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/exceptions.py", line 56, in http_error_handler
    yield None
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/api.py", line 119, in _check_http_error
    response.raise_for_status()
  File "/home/seb/.local/share/virtualenvs/test-env-NjLHGyVC/lib/python3.8/site-packages/requests/models.py", line 953, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://platform-api.bocco.me/v1/rooms/344293fc-7738-45d4-ba6c-998283c0b6de/messages/audio

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/api.py", line 119, in _check_http_error
    response.raise_for_status()
  File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/exceptions.py", line 59, in http_error_handler
    raise http_exception(e.response.json())
emo_platform.exceptions.UnauthorizedError: {'code': 'unauthorized', 'reason': 'JWT token is expired.'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/exceptions.py", line 56, in http_error_handler
    yield None
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/api.py", line 126, in _check_http_error
    response.raise_for_status()
  File "/home/seb/.local/share/virtualenvs/test-env-NjLHGyVC/lib/python3.8/site-packages/requests/models.py", line 953, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://platform-api.bocco.me/v1/rooms/344293fc-7738-45d4-ba6c-998283c0b6de/messages/audio

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "cmdline.py", line 140, in <module>
    d = room.send_audio_msg(file_path)
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/api.py", line 289, in send_audio_msg
    return self.base_client._post(
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/api.py", line 151, in _post
    return self._check_http_error(request, update_tokens=update_tokens)
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/api.py", line 126, in _check_http_error
    response.raise_for_status()
  File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/seb/Documents/yukai/bemo/platform-api/repository/emo-platform-api-python/emo_platform/exceptions.py", line 59, in http_error_handler
    raise http_exception(e.response.json())
emo_platform.exceptions.BadRequestError: {'audio': 'must not be null'}

NoRoomErrorを出すパターンの追加

  • listが空だった時も例外を出すようにする
  • apiでは実装済みでstash中
  • stash@{0}: On base_change_return_value: Raise no room exception when room is zero

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.