I am working on some API script in Python, it takes one argument and returns JSON. I am using BrawlStats library (https://github.com/SharpBit/brawlstats). It works very well in PyCharm but doesn't work in terminal, I have no idea why, I tried few suggestions like running "pip install" in script directory but it still doesn't help. I ma trying to run the script using PHP but it returns the same error as terminal: https://gyazo.com/afac3d7c7e50b4c4925ec767dc5457b2 + https://gyazo.com/5a55668e5e4cd005a64dd5c702043b98. Help would be really appreciated, I am stuck and I don't know how to fix it :/
Code:
import brawlstats
import json
import sys
client = brawlstats.Client("***")
def OMEGA(LUL):
player = client.get_profile(LUL)
xxDD = {
"tag": player.tag,
"name": player.name,
"avatar": player.avatar_url,
"trophies": player.trophies,
"victories": player.victories,
"level": player.exp_level
}
print(json.dumps(xxDD))
return json.dumps(xxDD)
print(sys.argv[1])
OMEGA(sys.argv[1])
and here is error when I run it using PHP/terminal:
Traceback (most recent call last):
File "C:/xampp/htdocs/main.py", line 23, in <module>
OMEGA(sys.argv[1])
File "C:/xampp/htdocs/main.py", line 8, in OMEGA
player = client.get_profile(LUL)
File "C:\Users\Krzysztof\AppData\Local\Programs\Python\Python36\lib\site-packages\brawlstats\core.py", line 147, in get_profile
data, resp = self._get(self.api.profile + '/' + tag)
File "C:\Users\Krzysztof\AppData\Local\Programs\Python\Python36\lib\site-packages\brawlstats\core.py", line 124, in _get
with self.session.get(url, timeout=self.timeout, headers=self.headers) as resp:
AttributeError: __enter__
Last thing, here is output when I run it using PyCharm:
{"tag": "CP0GU982", "name": "flick", "avatar": "https://fourjr.github.io/bs-assets/player_icons/28000000.png", "trophies": 6, "victories": 1, "level": 1}
Related
java version "1.8.0_311"
Python 3.10.8
Sikuli:-
<dependency>
<groupId>sikulixapi</groupId>
<artifactId>sikulixapi</artifactId>
<scope>system</scope>
<version>2.0.5</version>
<systemPath>${project.basedir}/sikulixapi-2.0.5.jar</systemPath>
</dependency>
I am getting the below error while running a sample python program from java.
Exception in thread "main" Traceback (most recent call last):
File "foo\boo\sikulixapi-2.0.5.jar\Lib\site.py", line 68, in <module>
File "foo\boo\sikulixapi-2.0.5.jar\Lib\os.py", line 64, in <module>
File "foo\boo\sikulixapi-2.0.5.jar\Lib\ntpath.py", line 12, in <module>
File "foo\boo\sikulixapi-2.0.5.jar\Lib\warnings.py", line 395, in <module>
File "foo\boo\sikulixapi-2.0.5.jar\Lib\warnings.py", line 395, in <module>
File "__pyclasspath__/_warnings.py", line 105, in <module>
NameError: name 'ResourceWarning' is not defined
Python:-
class Hello:
__gui = None
def __init__(self, gui):
self.__gui = gui
def run(self):
print('Hello world!')
Java
package Types.UserInterface.Utilities;
import org.python.core.PyInstance;
import org.python.util.PythonInterpreter;
public class InterpreterExample {
PythonInterpreter interpreter = null;
public InterpreterExample() {
PythonInterpreter.initialize(System.getProperties(),
System.getProperties(), new String[0]);
this.interpreter = new PythonInterpreter();
}
void execfile(final String fileName) {
this.interpreter.execfile(fileName);
}
PyInstance createClass(final String className, final String opts) {
return (PyInstance) this.interpreter.eval(className + "(" + opts + ")");
}
public static void main(String gargs[]) {
InterpreterExample ie = new InterpreterExample();
ie.execfile("hello.py");
PyInstance hello = ie.createClass("Hello", "None");
hello.invoke("run");
}
}
Not sure why it is conflicting with sikuli classes while running the sample java program.
Note: Python program works perfectly fine when they are executed directly. Problem raises only when the same program is called in java.
Could someone give a direction as to what is the approach to fix this?
cf Learning how to use Jython - ResourceWarning error
Jython currently only works with Python 2, you can't use Python 3 with it (for now), hence the error.
I'm using this Datastore API documentation and here is my code in Python:
class DatastoreConf:
def __init__(self):
self.datastore_client = datastore.Client()
def insert_entity(self):
complete_key = self.datastore_client.key("Task", "sampleTask")
task = datastore.Entity(key=complete_key)
task.update(
{
"category": "Personal",
"done": False,
"priority": 4,
"description": "Learn Cloud Datastore",
}
)
self.datastore_client.put(task)
d = DatastoreConf()
d.insert_entity()
I've already set GOOGLE_APPLICATION_CREDENTIALS variable to my service account key and I have sufficient roles, but I'm getting the error
TypeError: Expected a message object, but got kind: "Task" name: "sampleTask".
The traceback that I got is:
Traceback (most recent call last):
File "C:/Users/user/project/datastore_configuration.py", line 24, in <module>
d.get_entity()
File "C:/Users/user/project/datastore_configuration.py", line 21, in get_entity
self.datastore_client.put(task)
File "C:\Users\user\project\venv\lib\site-packages\google\cloud\datastore\client.py", line 575, in put
self.put_multi(entities=[entity], retry=retry, timeout=timeout)
File "C:\Users\user\projectvenv\lib\site-packages\google\cloud\datastore\client.py", line 612, in put_multi
current.put(entity)
File "C:\Users\user\project\venv\lib\site-packages\google\cloud\datastore\batch.py", line 227, in put
_assign_entity_to_pb(entity_pb, entity)
File "C:\Users\user\project\venv\lib\site-packages\google\cloud\datastore\batch.py", line 373, in _assign_entity_to_pb
bare_entity_pb = helpers.entity_to_protobuf(entity)
File "C:\Users\user\project\venv\lib\site-packages\google\cloud\datastore\helpers.py", line 207, in entity_to_protobuf
key_pb = entity.key.to_protobuf()
File "C:\Users\user\project\venv\lib\site-packages\google\cloud\datastore\key.py", line 298, in to_protobuf
key.path.append(element)
Do you have any idea what causes this error?
I resolved the problem. The error was due to version difference. Datastore worked with library protobuf 3.20.1 but didn't with 4.21.0.
I think it's beacause Firestore is now developed much more and the versions in Datastore are no longer supported.
First, my apologies as a Python newbie that I'm asking this question. It probably has nothing at all to do with convertapi and more to do with my basic lack of understanding as to how to interact with APIs.
I'm reading a Google sheet to find embedded hyperlinks containing references to files (PDF, html, whatever) and then using convertapi to get a txt version so that I can do content analysis based on existence, count and proximity of various terms.
My question has to do with the convertapi.convert failing because (in this case) it turns out convertapi thinks the PDF is invalid (because I have tested the file # convertapi.com and it returned a 5002 error). I don't dispute the file may be bad - all I want to do is detect that convertapi.convert can't convert the file so that I can ignore it and move on.
My python code has a small function:
def convert_PDF_to_text(inputfilename):
result = convertapi.convert('txt', { 'File': inputfilename }, from_format = 'pdf')
result.save_files('converted_pdf_files')
...and while it works fine for some inputs there is a particular URL PDF that results in this output (including my own messages from program):
about to call convertapi.convert with filename (https://www.epa.gov/sites/production/files/2016-06/documents/2016_policy_order_revision_6-10-16.pdf)
yes this is the specific file causing the problem: https://www.epa.gov/sites/production/files/2016-06/documents/2016_policy_order_revision_6-10-16.pdf
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/convertapi/client.py", line 46, in handle_response
r.raise_for_status()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://v2.convertapi.com/convert/pdf/to/txt?Secret=PIuLcqNVL8w4rc9Y
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./p1.py", line 244, in <module>
convert_PDF_to_text(source_URL)
File "./p1.py", line 63, in convert_PDF_to_text
result = convertapi.convert('txt', { 'File': inputfilename }, from_format = 'pdf')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/convertapi/api.py", line 7, in convert
return task.run()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/convertapi/task.py", line 26, in run
response = convertapi.client.post(path, params, timeout = timeout)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/convertapi/client.py", line 16, in post
return self.handle_response(r)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/convertapi/client.py", line 49, in handle_response
raise ApiError(r.json())
convertapi.exceptions.ApiError: <exception str() failed>
I know it should be obvious just from the errors what I should check...but I'm too much of a newbie to Python and APIs to know how to decipher.
How do I test for errors so that my Python code doesn't abort?
Thanks in advance and again sorry for the basic question - yes I did search for answers and don't find anyone addressing my question, it's likely too simple...
All - disregard. I used try: & except: to manage this.
I want to create cloud object storage using python API and referred to link https://sldn.softlayer.com/blog/waelriac/managing-softlayer-object-storage-through-rest-apis.
When I use following command to order CLOUD_OBJECT_STORAGE, it prompt errors. Did I miss some config or give the wrong config?
payload = '{"parameters" : [{"complexType": "SoftLayer_Container_Product_Order_Network_Storage_Hub", "quantity": 1, "packageId": 206, "prices": [{"id": 177725}]}]}'
client['SoftLayer_Product_Order'].placeOrder(payload)
client['SoftLayer_Product_Order'].placeOrder(payload)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/SoftLayer/API.py", line 392, in call_handler
return self(name, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer/API.py", line 360, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer/API.py", line 263, in call
return self.transport(request)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer/transports.py", line 195, in call
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Order_InvalidContainer): Invalid container specified: SoftLayer_Container_Product_Order. Ordering a server or service requires a specific container type, not the generic base order container.
well in order to call the Softlayer's API methods using the Soflayer's Python client the request are differents from REST request I recomend you to review documentation to get more information.
this is the code you need to use:
import SoftLayer
USERNAME="set me"
APIKEY="set me"
client = SoftLayer.create_client_from_env(
username=USERNAME,
api_key=APIKEY
)
order = {
"quantity": 1,
"packageId": 206,
"prices": [{
"id": 177725
}]
}
result = client['SoftLayer_Product_Order'].verifyOrder(order)
print (result)
Another thing to point out is that you need to make sure that you are using the correct price, the prices can be different for each account, so in order to make sure you are using the correct price I recomend you to call the SoftLayer_Product_Package:getItemPrices
Using Python use this:
result = client['SoftLayer_Product_Package'].getItemPrices(id=206)
print (result)
Regards
I am new to INDD CC Server. I have Implemented Indesign server running on Windows. I need to convert IDML to PDF but having issues.
I have used SimpleIDML Python library to manipulate Adobe(r) IDML(r) files.
My sample script is
I2P.py
from simple_idml.indesign import indesign
idml_file = "/home/user/Project/EPS/media/test/2-idml/test001.idml"
indd_file = "/home/user/Project/EPS/media/test/InDesigndocument/test001.indd"
url_path = "http://192.168.1.1:12345/"
client_dir = "/home/user/Project/EPS/media/source"
server_dir = "/home/user/Project/EPS/media/server"
response = indesign.save_as(indd_file, [{
"fmt": "pdf",
"params": {"colorSpace": "CMYK"},
}],
url_path,
client_dir,
server_dir)[0]
with open("my_file.pdf", "w+") as f:
f.write(response)
In documentation :
response = indesign.save_as("/path_to_file.indd", [{
"fmt": "pdf",
"params": {"colorSpace": "CMYK"},
}],
"http://url-to-indesign-server:port",
"/path/to/client/workdir",
"/path/to/indesign-server/workdir")[0]
When i run I2P script throws me error as :
Traceback (most recent call last):
File "ItoP.py", line 12, in <module>
server_path)[0]
File "/home/user/eps2_env/local/lib/python2.7/site-packages/simple_idml/indesign/indesign.py", line 71, in new_func
logger, logger_extra)
File "/home/user/eps2_env/local/lib/python2.7/site-packages/simple_idml/indesign/indesign.py", line 180, in save_as
responses = map(lambda fmt: _save_as(fmt), dst_formats_params)
File "/home/user/eps2_env/local/lib/python2.7/site-packages/simple_idml/indesign/indesign.py", line 180, in <lambda>
responses = map(lambda fmt: _save_as(fmt), dst_formats_params)
File "/home/user/eps2_env/local/lib/python2.7/site-packages/simple_idml/indesign/indesign.py", line 149, in _save_as
response = cl.service.RunScript(params)
File "/home/user/eps2_env/local/lib/python2.7/site-packages/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/home/user/eps2_env/local/lib/python2.7/site-packages/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/home/user/eps2_env/local/lib/python2.7/site-packages/suds/client.py", line 649, in send
result = self.failed(binding, e)
File "/home/user/eps2_env/local/lib/python2.7/site-packages/suds/client.py", line 702, in failed
r, p = binding.get_fault(reply)
File "/home/user/eps2_env/local/lib/python2.7/site-packages/suds/bindings/binding.py", line 265, in get_fault
raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'The specified script file can not be found: /home/user/Project/EPS/media/server/tmp9LVUWj/save_as.jsx'
Manually i can see dynamically created dir tmp9LVUWj inside server dir. Server path expecting on same time.
Not able to figure out how to set indesign-server/workdir and access in code and how to solve ? I have spend much time on this and not able find help or example code.
Or is there other python package to convert from IDML to PDF.
Thanks in advance
You wrote,
Manually I can see dynamically created dir tmp9LVUWj inside server
dir.
That is true, but that is not the error. It is stating that it cannot find a JSX file named save_as.jsx within that directory. Is that in fact the name of the JSX file that you were intending to place there, or the file that is residing there now?