Occasionally get "attempt to apply non-function" error when applying getForm - api

I'm using getForm to repeatedly pull data from an api. Sometimes the program finishes, and other times after some amount of iterations, I get the following error message:
Error in curlPerform(url = url, curl = curl, .opts = .opts) :
attempt to apply non-function
In addition: There were more than 50 warnings (use warnings() to see the first 50)
> traceback()
5: .Call("R_curl_easy_perform", curl, .opts, isProtected, .encoding,
PACKAGE = "RCurl")
4: curlPerform(url = url, curl = curl, .opts = .opts)
3: getURLContent(uri, .opts = .opts, .encoding = .encoding, binary = binary,
curl = curl)
2: getForm("https://xx", .params = parval)
1: fromJSON(getForm("https://xx",
.params = parval)) at #32
the warnings are:
In RCurlIconv(str, from = "C99", to = encoding) :
UTF-8 not supported iconv entries
Thanks for your help!

It's just a download error, sometimes the download fails. I just put in a provision to try the download again in that case.

Related

Unpack for type ((67108864,)) not implemented

I'm trying to query an MQ server running on IBM i from a python script on a linux box. I'm getting this error back from pymqi and I don't know what it means.
The stacktrace is as follows:
[{"message": "Unpack for type ((67108864,)) not implemented", "traceback":
"Traceback (most recent call last):\n
response = pcf.MQCMD_INQUIRE_CHANNEL(args)
File \"../python3.8/site-packages/pymqi/__init__.py\",
line 2770, in __call__\n
res, mqcfh_response = self.__pcf.unpack(message)
This is the snippet of code that generates the error
cd = pymqi.CD()
cd.ChannelName = pymqi.ensure_bytes(channel)
cd.ConnectionName = pymqi.ensure_bytes("{}({})".format(host, port))
cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
cd.TransportType = pymqi.CMQC.MQXPT_TCP
cd.Version = 9
queue_manager = pymqi.QueueManager(None)
queue_manager.connect_with_options(queue_manager_name, cd)
args = {pymqi.CMQCFC.MQCACH_CHANNEL_NAME: pymqi.ensure_bytes('*')}
pcf = pymqi.PCFExecute(queue_manager, response_wait_interval=5, convert=False)
response = pcf.MQCMD_INQUIRE_CHANNEL(args)
What is type 67108864?
I know there are limitations with this library and connecting to a z/OS, are there similar limitations with IBM i?
Turns out IBM i along with AIX have a different endinaness so one must pass convert=True to the pymqi.PCFExecute commands
queue_manager = pymqi.QueueManager(None)
queue_manager.connect_with_options(queue_manager_name, cd)
args = {pymqi.CMQCFC.MQCACH_CHANNEL_NAME: pymqi.ensure_bytes('*')}
pcf = pymqi.PCFExecute(queue_manager, response_wait_interval=5, convert=True)
response = pcf.MQCMD_INQUIRE_CHANNEL(args)

Changes in lua language cause error in ai script

When I run script in game, I got an error message like this:
.\AI\haick.lua:104: bad argument #1 to 'find' (string expected, got nill)
local haick = {}
haick.type = type
haick.tostring = tostring
haick.require = require
haick.error = error
haick.getmetatable = getmetatable
haick.setmetatable = setmetatable
haick.ipairs = ipairs
haick.rawset = rawset
haick.pcall = pcall
haick.len = string.len
haick.sub = string.sub
haick.find = string.find
haick.seed = math.randomseed
haick.max = math.max
haick.abs = math.abs
haick.open = io.open
haick.rename = os.rename
haick.remove = os.remove
haick.date = os.date
haick.exit = os.exit
haick.time = GetTick
haick.actors = GetActors
haick.var = GetV
--> General > Seeding Random:
haick.seed(haick.time())
--> General > Finding Script Location:
local scriptLocation = haick.sub(_REQUIREDNAME, 1, haick.find(_REQUIREDNAME,'/[^\/:*?"<>|]+$'))
Last line (104 in file) causes error and I don`t know how to fix it.
There are links to .lua files below:
https://drive.google.com/file/d/1F90v-h4VjDb0rZUCUETY9684PPGw7IVG/view?usp=sharing
https://drive.google.com/file/d/1fi_wmM3rg7Ov33yM1uo7F_7b-bMPI-Ye/view?usp=sharing
Help, pls!
When you use a function in Lua, you are expected to pass valid arguments for the function.
To use a variable, you must first define it, _REQUIREDNAME in this case is not available, haick.lua file is incomplete. The fault is of the author of the file.
Lua has a very useful reference you can use if you need help, see here

Invalid Runame In eapy api in getiing session

I am trying to get the ebay session id from ebay python sdk. When i make request to the api. I am getting the error invalid ru_name. I have cross checked with name. It's correct.
This is my GetSession python code, Works good for me.
from ebaysdk.exception import ConnectionError
from ebaysdk.trading import Connection as Trading
myRuName = "XXXXXXXXXXXXMyRuNameXXXXXXXXXXXXXXXXXX"
myAppID = "XXXXXXXXXXXXXMyAppIDXXXXXXXXXXXXXXXXXXX"
myDevID = "XXXXXXXXXXXXXMyDevIDXXXXXXXXXXXXXXXXXX"
myCertID = "XXXXXXXXXXXXXXMyCertIDXXXXXXXXXXXXXXXX"
myFlags = {'RuName': myRuName}
try:
api = Trading(config_file=None, appid=myAppID, devid=myDevID, certid=myCertID)
response = api.execute('GetSessionID',myFlags)
print 'SessionID = '+response.reply.SessionID
except ConnectionError as e:
print(e)
print(e.response.dict())
Hope this helps.

Sending form data with an HTTP PUT request using Grinder API

I'm trying to replicate the following successful cURL operation with Grinder.
curl -X PUT -d "title=Here%27s+the+title&content=Here%27s+the+content&signature=myusername%3A3ad1117dab0ade17bdbd47cc8efd5b08" http://www.mysite.com/api
Here's my script:
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from net.grinder.plugin.http import HTTPRequest
from HTTPClient import NVPair
import hashlib
test1 = Test(1, "Request resource")
request1 = HTTPRequest(url="http://www.mysite.com/api")
test1.record(request1)
log = grinder.logger.info
test1.record(log)
m = hashlib.md5()
class TestRunner:
def __call__(self):
params = [NVPair("title","Here's the title"),NVPair("content", "Here's the content")]
params.sort(key=lambda param: param.getName())
ps = ""
for param in params:
ps = ps + param.getValue() + ":"
ps = ps + "myapikey"
m.update(ps)
params.append(NVPair("signature", ("myusername:" + m.hexdigest())))
request1.setFormData(tuple(params))
result = request1.PUT()
The test runs okay, but it seems that my script doesn't actually send any of the params data to the API, and I can't work out why. There are no errors generated, but I get a 401 Unauthorized response from the API, indicating that a successful PUT request reached it, but obviously without a signature the request was rejected.
This isn't exactly an answer, more of a workaround that I came up with, that I've decided to post since this question hasn't yet received any responses, and it may help anyone else trying to achieve the same thing.
The workaround is basically to use the httplib and urllib modules to build and make the PUT request instead of the HTTPClient module.
import hashlib
import httplib, urllib
....
params = [("title", "Here's the title"),("content", "Here's the content")]
params.sort(key=lambda param: param[0])
ps = ""
for param in params:
ps = ps + param[1] + ":"
ps = ps + "myapikey"
m = hashlib.md5()
m.update(ps)
params.append(("signature", "myusername:" + m.hexdigest()))
params = urllib.urlencode(params)
print params
headers = {"Content-type": "application/x-www-form-urlencoded"}
conn = httplib.HTTPConnection("www.mysite.com:80")
conn.request("PUT", "/api", params, headers)
response = conn.getresponse()
print response.status, response.reason
print response.read()
conn.close()
(Based on the example at the bottom of this documentation page.)
You have to refer to the multi-form posting example in Grinder script gallery, but changing the Post to Put. It works for me.
files = ( NVPair("self", "form.py"), )
parameters = ( NVPair("run number", str(grinder.runNumber)), )
# This is the Jython way of creating an NVPair[] Java array
# with one element.
headers = zeros(1, NVPair)
# Create a multi-part form encoded byte array.
data = Codecs.mpFormDataEncode(parameters, files, headers)
grinder.logger.output("Content type set to %s" % headers[0].value)
# Call the version of POST that takes a byte array.
result = request1.PUT("/upload", data, headers)

python3 urllib.request.urlopen timeout error

i have script witch gets data from site. First i wrote it in 2.7 python and its works.
When i rewrite it to python3 i have problem.
In python2.7 that works fine
for x in xrange(len(ll.string2)-1):
psR = urllib2.urlopen(ll.string2[x]).read()
nrL = Przystanek()
nrL.feed(psR)
self.BusExtData += nrL.string2
python3
for x in range(len(ll.string2)-1):
psR = urllib.request.urlopen(ll.string2[x],timeout=3000).read().decode('iso-8859-2')
nrL = Przystanek()
nrL.feed(psR)
self.BusExtData += nrL.string2
Upper code generate timeout error.
i = 0
while i<(len(ll.string2)-1):
try:
psR = urllib.request.urlopen(ll.string2[i],timeout=3000).read().decode('iso-8859-2')
nrL = Przystanek()
nrL.feed(psR)
self.BusExtData += nrL.string2
i=i+1
except:
print("Error")
i=i-1
pass
I avoid this problem with upper case. But i dont know why urllib2.urlopen dont make timeout error. When i use urllib.request.urlopen i get this error message:
urllib.error.URLError:urlopen error timed out
or
urllib.error.URLError:urlopen error timed out [WinError 10060]
What is difference between urlib2.urlopen and urllib.request.urlopen?