Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I tried to pass a bytearray but it went wrong #8

Closed
qczrzl opened this issue Jun 22, 2018 · 5 comments
Closed

I tried to pass a bytearray but it went wrong #8

qczrzl opened this issue Jun 22, 2018 · 5 comments

Comments

@qczrzl
Copy link

qczrzl commented Jun 22, 2018

tim 20180622182921
msg = messaging.RemotingMessage(
messageId=str(uuid.uuid1()).upper(),
clometOd=None,
operation='findBizObjEx',
destination='superSystemFacadeService',
timeTolive=0,
timestamp=0
)
string = "78daa5524d6fd33018fe2b93cf69643b8d49bc5"
userDtoBytes = bytearray(string, encoding='utf-8')
msg.headers['userDtoBytes'] = userDtoBytes"
userDtoBytes = bytearray(string, encoding='utf-8')
msg.headers['userDtoBytes'] = userDtoBytes

I tried to construct this request but an exception was thrown!
Seems to be an argument that does not support passing a bytearray
I hope to get your reply

Traceback (most recent call last):
File "C:/Users/EDZ/PycharmProjects/untitled1/pyamf_test.py", line 62, in
ihotel_spider.construct_flex_message()
File "C:/Users/EDZ/PycharmProjects/untitled1/pyamf_test.py", line 56, in construct_flex_message
bin_msg = remoting.encode(ev)
File "C:\Users\EDZ\Envs\py2\lib\site-packages\pyamf\remoting_init_.py", line 724, in encode
write_body(name, message, stream, encoder, strict)
File "C:\Users\EDZ\Envs\py2\lib\site-packages\pyamf\remoting_init
.py", line 550, in _write_body
encode_body(message)
File "C:\Users\EDZ\Envs\py2\lib\site-packages\pyamf\remoting_init
.py", line 523, in _encode_body
encoder.writeElement(x)
File "cpyamf/codec.pyx", line 623, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10902)
File "cpyamf/codec.pyx", line 629, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10661)
File "cpyamf/amf0.pyx", line 581, in cpyamf.amf0.Encoder.handleBasicTypes (cpyamf\amf0.c:7975)
File "cpyamf/amf0.pyx", line 577, in cpyamf.amf0.Encoder.writeAMF3 (cpyamf\amf0.c:7917)
File "cpyamf/codec.pyx", line 645, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10786)
File "cpyamf/amf3.pyx", line 930, in cpyamf.amf3.Encoder.writeObject (cpyamf\amf3.c:11500)
File "cpyamf/codec.pyx", line 629, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10661)
File "cpyamf/amf3.pyx", line 1034, in cpyamf.amf3.Encoder.handleBasicTypes (cpyamf\amf3.c:12466)
File "cpyamf/codec.pyx", line 587, in cpyamf.codec.Encoder.handleBasicTypes (cpyamf\codec.c:9961)
File "cpyamf/amf3.pyx", line 790, in cpyamf.amf3.Encoder.writeDict (cpyamf\amf3.c:10088)
File "cpyamf/codec.pyx", line 645, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10786)
File "cpyamf/amf3.pyx", line 911, in cpyamf.amf3.Encoder.writeObject (cpyamf\amf3.c:11322)
File "C:\Users\EDZ\Envs\py2\lib\site-packages\pyamf\alias.py", line 404, in getEncodableAttributes
return obj.dict.copy()
AttributeError: 'bytearray' object has no attribute 'dict'

@qczrzl qczrzl closed this as completed Jun 22, 2018
@qczrzl qczrzl reopened this Jun 22, 2018
@StdCarrot
Copy link
Owner

It seems to use Python2.x
This project only support Python3.
Can you make sure where your code run on?

@qczrzl
Copy link
Author

qczrzl commented Jun 25, 2018

Sorry, the above code may mislead you
The above code is run on Python2 using the pyamf library

I also tried it on python3, throwing the same exception
It's uses the py3amf library, And, I used Python3.5.4

Traceback (most recent call last):
File "C:/GitWorkSpace/comments_spider/py3rmf_test.py", line 72, in
data = ihotel_spider.construct_flex_message()
File "C:/GitWorkSpace/comments_spider/py3rmf_test.py", line 54, in construct_flex_message
bin_msg = remoting.encode(ev)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\remoting_init_.py", line 724, in encode
write_body(name, message, stream, encoder, strict)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\remoting_init
.py", line 550, in _write_body
encode_body(message)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\remoting_init
.py", line 523, in _encode_body
encoder.writeElement(x)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\codec.py", line 576, in writeElement
func(data)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\amf0.py", line 676, in writeAMF3
self.context.getAMF3Encoder(self).writeElement(data)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\codec.py", line 576, in writeElement
func(data)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\amf3.py", line 1509, in writeObject
self.writeElement(value)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\codec.py", line 576, in writeElement
func(data)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\amf3.py", line 1521, in writeObject
self.writeElement(value)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\codec.py", line 576, in writeElement
func(data)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\amf3.py", line 1500, in writeObject
attrs = alias.getEncodableAttributes(obj, codec=self)
File "C:\Users\EDZ\Envs\spider\lib\site-packages\pyamf\alias.py", line 404, in getEncodableAttributes
return obj.dict.copy()
AttributeError: 'bytearray' object has no attribute 'dict'

@StdCarrot
Copy link
Owner

StdCarrot commented Jun 25, 2018

Ok, I understand finally what you want to.
If you want to use ByteArray type on AMF, it doesn't mean bytearray on Python.
ByteArray is AMF specific type, so, if you want to use it, you must use ByteArray class in lib.
See this page, line 363.
https://github.com/StdCarrot/Py3AMF/blob/master/pyamf/tests/test_amf3.py
There is how to use ByteArray in Py3AMF or PyAMF.

@qczrzl
Copy link
Author

qczrzl commented Jun 25, 2018

Thanks for your answer, the problem was solved successfully

@qczrzl qczrzl closed this as completed Jun 25, 2018
@benci042
Copy link

Thanks for your answer, the problem was solved successfully

Hello
I has same issule with your met. Hope to get your help.
Would you please give me some demo code ,thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants