erlang rfc4627 decode error - erlang

I am trying to decode json data in yaws, getting an error which is not clear to identify the issue. The Json data is
{
"airport": [
{"airport": "MAA"},
{"city": "Chennai"},
{"country": "India"},
{"name": "Anna International Airport"}
]
}
The command i am using is
{ok, Json, _} = rfc4627:decode(Arg#arg.clidata).
The error is
Exception: undef Req:
{http_request,'POST',{abs_path,"/sample/rest.yaws"},{1,1}} Stack:
[{rfc4627,decode,
[<<"{\n \"airport\": [\n {\"airport\": \"MAA\"},\n {\"city\": \"Chennai\"},\n {\"country\":
\"India\"},\n {\"name\": \"Anna International Airport\"}\n
]\n}">>],
[]},

You're getting an undef exception, indicating that you're calling an undefined function. The error shows the stack, and at the top of the stack is the rfc4627:decode/1 function; that's the one that's undefined.
My guess is that your load path does not include the directory where you've stored the compiled rfc4627 module. You can add that directory to the Yaws load path by modifying your yaws.conf file and adding something like the following to the global config section (near the top):
ebin_dir = /path/to/where/rfc4627/is/stored
Note that you're allowed to have multiple ebin_dir settings; each is added to the load path.

Related

Service __len__ not found Unexpected error, recovered safely

python3.8
My code:
from googleads import adwords
def execute_request():
adwords_client = adwords.AdWordsClient.LoadFromStorage(path="google_general/googleads.yaml")
campaign_service = adwords_client.GetService('CampaignService', version='v201809')
pass
context["dict_list"] = execute_request()
Traceback:
Traceback (most recent call last):
File "/home/michael/pycharm-community-2019.3.2/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_xml.py", line 282, in frame_vars_to_xml
xml += var_to_xml(v, str(k), evaluate_full_value=eval_full_val)
File "/home/michael/pycharm-community-2019.3.2/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_xml.py", line 369, in var_to_xml
elif hasattr(v, "__len__") and not is_string(v):
File "/home/michael/PycharmProjects/ads3/venv/lib/python3.8/site-packages/googleads/common.py", line 694, in __getattr__
raise googleads.errors.GoogleAdsValueError('Service %s not found' % attr)
googleads.errors.GoogleAdsValueError: Service __len__ not found
Unexpected error, recovered safely.
googleads.yaml about logging
logging:
version: 1
disable_existing_loggers: False
formatters:
default_fmt:
format: ext://googleads.util.LOGGER_FORMAT
handlers:
default_handler:
class: logging.StreamHandler
formatter: default_fmt
level: DEBUG
loggers:
# Configure root logger
"":
handlers: [default_handler]
level: DEBUG
I've just started studying the API.
Namely, I'm trying to execute my first request (https://developers.google.com/adwords/api/docs/guides/first-api-call#make_your_first_api_call)
Could you help me with this problem? At least how to localize it more precisely.
This seems to be a problem which results from the way the PyCharm debugger inspects live objects during debugging.
Specifically, it checks if a given object has the __len__ attribute/method in the code of var_to_xml, most likely to determine an appropriate representation of the object for the debugger interface (which seems to require constructing an XML representation).
googleads service objects such as your campaign_service, however, use some magic to be able to call the defined SOAP methods on them without requiring to hard-code all of them. The code looks like this:
def __getattr__(self, attr):
"""Support service.method() syntax."""
if self._WsdlHasMethod(attr):
if attr not in self._method_proxies:
self._method_proxies[attr] = self._CreateMethod(attr)
return self._method_proxies[attr]
else:
raise googleads.errors.GoogleAdsValueError('Service %s not found' % attr)
This means that the debugger's check for a potential __len__ attribute is intercepted, and because the CampaignService does not have a SOAP operation called __len__, an exception is raised.
You can validate this by running your snippet in the regular way (i.e. not debugging it) and checking if that works.
An actual fix would seem to either require that PyCharm's debugger changes the way it inspects objects (not calling hasattr(v, "__len__")) or that googleads modifies the way it implements __getattr__, for example by actually implementing a __len__ method that just raises AttributeError.

How to add to a Lua DissectorTable?

I'm writing a Lua dissector for Wireshark for a complex protocol. The protocol has a message header that includes a msgType field. I want to write a subdissector for each message type, with each subdissector stored in a separate source file.
My top-level script is general.lua which dissects the message header and creates the dissector table:
DissectorTable.new("myProtocol.Message")
dofile(DATA_DIR.."cplane.lua")
cplane.lua is a subdissector for message type 'cplane' and includes the code:
my_dissector_table = DissectorTable.get("myProtocol.Message")
my_dissector_table:add(0x02, myProtocol_cplane_proto)
Both scripts are in the same subdirectory of Wireshark's plugins directory.
When I load the plugins I get error:
Lua: Error during loading:
[string "C:\Program Files (x86)\Wireshark\plugins\2.4...."]:9: bad argument
#1 to 'get' (DissectorTable_get: no such dissector_table)
Lua: Error during loading:
[string "C:\Program Files (x86)\Wireshark\plugins\2.4...."]:170: bad
argument #1 to 'dofile' (dofile: file does not exist)
How can I fix this? Is the problem to do with the loading order of the scripts? Is the dofile() call necessary?
It is not necessary to use dofile as all scripts in the plugins directory are loaded. The order of loading is however not fixed (at least, it is not documented to be fixed). Currently Lua plugins are loaded after other dissectors, so trying to lookup dissector tables in the "global scope" will only work for built-in dissectors, such as tcp.port:
local myproto = Proto("myproto", "My Protocol")
function myproto.dissector(tvb, pinfo, tree)
...
end
-- Register with a built-in dissector table
DissectorTable.get("tcp.port"):add(1234, myproto)
For registering with custom dissector tables, this registration has to be deferred. In C dissectors, you would put the registration in proto_reg_handoff_PROTOABBREV (where PROTOABBREV should be substituted accordingly), but in Lua there is no such function.
The closest you can get is the "init" routine (a property of the Proto class, proto.init). These are called when a capture file is opened, before dissecting any packets. Example:
function myproto.init()
DissectorTable.get("your-custom-table"):add(1234, myproto)
end
Lua: Error during loading: [string "C:\Program Files
(x86)\Wireshark\plugins\2.4...."]:9: bad argument
#1 to 'get' (DissectorTable_get: no such dissector_table)
Answer: This error means that Dissector table is not found. Reason could be that the path is not correct, or the sequence of the file execution.
Lua: Error during loading: [string "C:\Program Files
(x86)\Wireshark\plugins\2.4...."]:170: bad argument #1 to 'dofile'
(dofile: file does not exist)
Answer: For me this error is gone by entering the exactly correct path

Ejabberd module do not compile after update

I, i have updated ejabberd from 16.01 to 16.03, i have a problem with my module, before update this line of code
Type = Packet#xmlel.attrs,
io:format("types:~p~n" , [Type]),
%Get raw data of message
Message = xml:element_to_binary(Packet).
works fine, now after update produce this:
types:[{<<"type">>,<<"chat">>}, {<<"to">>,<<"154#node0.frind.it">>},
{<<"from">>,<<"121#node0.frind.it">>}]
16:57:13.393 [error]
{undef,
[{xml,element_to_binary,
[{xmlel,<<"message">>,
[{<<"type">>,<<"chat">>},
{<<"to">>,<<"154#node0.frind.it">>},
{<<"from">>,<<"121#node0.frind.it">>}],
[{xmlel,<<"composing">>,
[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],
[]}]}], []},
{ejabberd_hooks,safe_apply,3,
[{file,"src/ejabberd_hooks.erl"},{line,382}]},
{ejabberd_hooks,run1,3,
[{file,"src/ejabberd_hooks.erl"},{line,329}]},
{ejabberd_sm,route,3,
[{file,"src/ejabberd_sm.erl"},{line,114}]},
{ejabberd_local,route,3,
[{file,"src/ejabberd_local.erl"},{line,112}]},
{ejabberd_router,route,3,
[{file,"src/ejabberd_router.erl"},{line,77}]},
{ejabberd_c2s,check_privacy_route,5,
[{file,"src/ejabberd_c2s.erl"},{line,2110}]},
{ejabberd_c2s,session_established2,2,
[{file,"src/ejabberd_c2s.erl"},{line,1271}]}]}
running hook:
{offline_message_hook,
[{jid,<<"121">>,<<"node0.frind.it">>,
<<"97395769126380428951460048231139020">>,<<"121">>,
<<"node0.frind.it">>,
<<"97395769126380428951460048231139020">>},
{jid,<<"154">>,<<"node0.frind.it">>,<<>>,<<"154">>,
<<"node0.frind.it">>,<<>>},
{xmlel,<<"message">>,
[{<<"type">>,<<"chat">>},
{<<"to">>,<<"154#node0.frind.it">>},
{<<"from">>,<<"121#node0.frind.it">>}],
[{xmlel,<<"composing">>,
[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],[]}]}
]}
Anyone can help me?
Latest ejabberd move to library fast_xml. Use fxml module instead of xml.

YAWs embedded with appmod not working for me

Alright, what am I doing wrong here. I'm trying the simple example of embedded YAWs from http://yaws.hyber.org/embed.yaws but with an appmod. I've added the my_app.erl file and compiled it. It works if not in embedded YAWs so I think it is specific to embedded.
-module(ybed).
-compile(export_all).
start() ->
{ok, spawn(?MODULE, run, [])}.
run() ->
Id = "embedded",
GconfList = [{ebin_dir, ["/Users/someuser/yawsembedded/ebin"]}],
Docroot = "/Users/someuser/yawstest",
SconfList = [{port, 8888},
{listen, {0,0,0,0}},
{docroot, Docroot},
{appmods, [{"/", my_app}]}
],
{ok, SCList, GC, ChildSpecs} =
yaws_api:embedded_start_conf(Docroot, SconfList, GconfList),
[supervisor:start_child(ybed_sup, Ch) || Ch <- ChildSpecs],
yaws_api:setconf(GC, SCList),
{ok, self()}.
Getting this Error:
ERROR erlang code threw an uncaught exception:
File: appmod:0
Class: error
Exception: undef
Req: {http_request,'GET',{abs_path,"/demo"},{1,1}}
Stack: [{my_app,out,
[{arg,#Port<0.2721>,
{{127,0,0,1},63720},
{headers,"keep-alive",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"0.0.0.0:8888",undefined,undefined,undefined,undefined,
undefined,undefined,undefined,
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0",
undefined,[],undefined,undefined,undefined,undefined,
undefined,undefined,undefined,undefined,
[{http_header,0,"Dnt",undefined,"1"},
{http_header,10,'Accept-Encoding',undefined,
"gzip, deflate"},
{http_header,11,'Accept-Language',undefined,"null"}]},
{http_request,'GET',{abs_path,"/demo"},{1,1}},
{http_request,'GET',{abs_path,"/demo"},{1,1}},
undefined,"/demo",undefined,undefined,
"/Users/someuser/yawstest","/",
"/Users/someuser/yawstest/demo",undefined,undefined,
<0.63.0>,[],"/","/",undefined}],
[]},
{yaws_server,deliver_dyn_part,8,
[{file,"yaws_server.erl"},{line,2818}]},
{yaws_server,aloop,4,[{file,"yaws_server.erl"},{line,1232}]},
{yaws_server,acceptor0,2,[{file,"yaws_server.erl"},{line,1068}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]
The stack trace shows that your my_app:out/1 function is getting called, but you're getting an undef exception. This is occurring because the runtime can't find the my_app:out/1 function, which means either it can't find the module or the module exists but does not export an out/1 function. For example, I was able to duplicate the error using the example code by not providing a my_app module.
First, make sure your my_app.erl file exports an out/1 function. Here's a trivial one that just returns a 405 error for all requests:
-module(my_app).
-export([out/1]).
out(_Arg) ->
{status, 405}.
Compile your my_app.erl file and put the compiled my_app.beam file either in a load path already known to the Erlang runtime, or in a directory you add to the load path. In your code it appears you're trying the latter approach, since you're specifically adding an ebin_dir with this Yaws global configuration directive:
GconfList = [{ebin_dir, ["/Users/someuser/yawsembedded/ebin"]}],
You need to verify that the /Users/someuser/yawsembedded/ebin directory exists, and that the compiled my_app.beam file is located there.

Erlang with Erlsom and DTD

I am trying to work with 1 GB XML and DTD file with Erlsom.
The problem is that parse_sax throws an exception becuase it cannot work with DTD file.
Basically i don't need this information so my question is how i tell the
sax_parser to just ignore this?
or even to use try and catch and when the error got catches then to skip this place on the file and continue from there.
This the exception:
** exception throw: {error,"Malformed: unknown reference: uuml"}
in function erlsom_sax_latin1:nowFinalyTranslate/3 (src/erlsom_sax_latin1.erl, line 1051)
in call from erlsom_sax_latin1:translateReferenceNonCharacter/4 (src/erlsom_sax_latin1.erl, line 1024)
in call from erlsom_sax_latin1:parseTextNoIgnore/3 (src/erlsom_sax_latin1.erl, line 922)
in call from erlsom_sax_latin1:parseContent/2 (src/erlsom_sax_latin1.erl, line 898)
in call from erlsom_sax_latin1:parse/2 (src/erlsom_sax_latin1.erl, line 172)
in call from mapReduce:run/0 (/home/alon/workspace/mapReduce/src/mapReduce.erl, line 26)(mapReduce#alon-Vostro-3300)2>
The problem is with "uuml" because in the XML file its apear with &uuml
Thanks for your help.
Hit the same error and found this in the ErlSom docs under limitations of the sax parser:
It doesn’t support entities, apart from the predefined ones (< etc.) and character references (&#nnn; and &#xhhh;).

Resources