2

私はかなり単純なユースケースを持っていますが、受け取ったエラーメッセージを理解していません.

私はリクエストと pyral モジュールを使用しています。pyral ( http://pyral.readthedocs.io/en/latest/interface.html# ) は、Rally の Restful API の単なるラッパーです。私の目標は、Rally (CA 製品) の UserStory からファイル (添付ファイル) を取得し、それをローカル ファイル システムに保存することです。

コンテキストとして、ここに私の環境設定を示します (Rally に認証してオブジェクトを作成します)。明らかに認証情報を削除しました。

from pyral import Rally, rallyWorkset

options = [arg for arg in sys.argv[1:] if arg.startswith('--')]
args = [arg for arg in sys.argv[1:] if arg not in options]
server, user, password, apikey, workspace, project = rallyWorkset(options)
rally = Rally(server='rally1.rallydev.com', 
user='**********', password='***********', 
          apikey="**************",
          workspace='**************', project='**************',
          server_ping=False)

その後、たった 1 つのユーザー ストーリーの応答オブジェクトを取得します (US845 のクエリを参照)。問題を単純化するためにこれを行います。

r = rally.get('UserStory', fetch = True, projectScopeDown=True, query = 'FormattedID = US845')

次に、組み込みイテレーターを使用して、RallyRESTResponse オブジェクトからユーザー ストーリーを取得します。

us = r.next()

そこから、成果物 (私たち) とファイル名 (添付ファイルの名前) を受け入れる getAttachment() メソッドを簡単に使用できるようになるはずだと感じています。getAttachmentNames(us) を使用して、添付ファイル名のリストを返すことができます。次のようなことをしようとすると問題が発生します

attachment_names = rally.getAttachmentNames(us) #get attachments for this UserStory
attachment_file = rally.getAttachment(us, attachment_names[0]) #Try to get the first attachment 

このようなエラーを返します

Traceback (most recent call last):

File "<ipython-input-81-a4a342a59c5a>", line 1, in <module>
attachment_file = rally.getAttachment(us, attachment_names[0])

File "C:\Miniconda3\lib\site-packages\pyral\restapi.py", line 1700, in getAttachment
att.Content = base64.decodebytes(att_content.Content)  # maybe further txfm to Unicode ?

File "C:\Miniconda3\lib\base64.py", line 552, in decodebytes
_input_type_check(s)

File "C:\Miniconda3\lib\base64.py", line 520, in _input_type_check
raise TypeError(msg) from err

TypeError: expected bytes-like object, not str

使用しようとすると、同様のエラーが表示されます

test_obj = rally.getAttachments(us)

次のようなエラーが返されます。

Traceback (most recent call last):

File "<ipython-input-82-06a8cd525177>", line 1, in <module>
rally.getAttachments(us)

File "C:\Miniconda3\lib\site-packages\pyral\restapi.py", line 1721, in getAttachments
attachments = [self.getAttachment(artifact, attachment_name) for attachment_name in attachment_names]

File "C:\Miniconda3\lib\site-packages\pyral\restapi.py", line 1721, in <listcomp>
attachments = [self.getAttachment(artifact, attachment_name) for attachment_name in attachment_names]

File "C:\Miniconda3\lib\site-packages\pyral\restapi.py", line 1700, in getAttachment
att.Content = base64.decodebytes(att_content.Content)  # maybe further txfm to Unicode ?

File "C:\Miniconda3\lib\base64.py", line 552, in decodebytes
_input_type_check(s)

File "C:\Miniconda3\lib\base64.py", line 520, in _input_type_check
raise TypeError(msg) from err

TypeError: expected bytes-like object, not str

このメソッドに必要なパラメーターを根本的に誤解しているようです。以前にこれを成功させた人はいますか?上記のようなワークフローで addAttachment() メソッドを使用しても問題はありません。bytes() メソッドを使用してファイル名 (文字列) を utf-8 に変換しようとしましたが、役に立ちませんでした。

pyral ソースのこの例も見ましたが、実行しようとするとまったく同じエラーが発生します。

https://github.com/klehman-rally/pyral/blob/master/examples/get_attachments.py

4

2 に答える 2