I'm having some trouble with SalesForce, I've never used it before so I'm not entirely sure what is going wrong here. I am using the simple_salesforce python module. I have successfully pulled data from SalesForce standard objects, but this custom object is giving me trouble. My query is
result = sf.query("Select Name from Call_Records__c")
which produces this error:
Traceback (most recent call last):
File "simple.py", line 15, in <module>
result = sf.query("Select Name from Call_Records__c")
File "/usr/local/lib/python2.7/dist-packages/simple_salesforce/api.py", line 276, in query
_exception_handler(result)
File "/usr/local/lib/python2.7/dist-packages/simple_salesforce/api.py", line 634, in _exception_handler
raise exc_cls(result.url, result.status_code, name, response_content)
simple_salesforce.api.SalesforceMalformedRequest: Malformed request https://sandbox.company.com/services/data/v29.0/query/?q=Select+Name+from+Call_Records__c. Response content: [{u'errorCode': u'INVALID_TYPE', u'message': u"\nSelect Name from Call_Records__c\n ^\nERROR at Row:1:Column:18\nsObject type 'Call_Records__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name.
Please reference your WSDL or the describe call for the appropriate names."}]
I've tried it with and without the __c for both the table name and the field name, still can't figure this out. Anything blatantly wrong?
Make sure your result is Call_Records__c/CallRecords__c
Call_Records__c result = sf.query("Select Name from Call_Records__c")
Or
CallRecords__c result = sf.query("Select Name from CallRecords__c")
Try using -
result = sf.query("Select Name from CallRecords__c")
Related
I have the following code running on AWS lambda, but getting the following error.
Error
[ERROR] AttributeError: 'str' object has no attribute 'source_instructions'
Traceback (most recent call last):
File "/var/task/gremlin_python/driver/driver_remote_connection.py", line 56, in submit
result_set = self._client.submit(bytecode, request_options=self._extract_request_options(bytecode))
File "/var/task/gremlin_python/driver/driver_remote_connection.py", line 81, in _extract_request_options
options_strategy = next((x for x in bytecode.source_instructionsEND RequestId: 4ee8073c-e941-43b3-8014-8717893b3188
Source code
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
def test_neptune(host):
remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin','g'.format(host))
query = "g.V().groupCount().by(label).unfold().project('label','count').by(keys).by(values)"
response = remoteConn.submit(query)
print("response-> {}" .format(response))
# iterate repsonse
# go thru label
for set_item in response:
for item in set_item:
print("item-> item: {}".format(item))
remoteConn.close()
test_neptune()
Your DriverRemoteConnection call is wrong. You have:
remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin','g'.format(host))
So you are sending {} as the hostname, and passing 'g' as a second parameter, which is probably where the error comes from. I don't know what you intended the 'g' for, but you probably want:
remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin'.format(host))
If you send the query as a text string you need to create the Client object differently or write the query as in-line Python. There are two examples at (1) and (2) that show each option. The error you are seeing is because the server is trying to find Gremlin bytecode in the packet sent but only found a string (which does not have a source_instructions method).
Using a DriverRemoteConnection you can use a Python line of code such as:
result = (g.V().groupCount().
by(label).
unfold().
project('label','count').
by(keys).
by(values).
next())
If you actually want/need to send the query as a string instead of bytecode, please see my answer to this question
https://github.com/krlawrence/graph/blob/master/sample-code/basic-client.py
https://github.com/krlawrence/graph/blob/master/sample-code/glv-client.py
I am using the Google Places API with Python to build a chatbot application to suggest nearby places.
I am referring to the below link:
https://github.com/slimkrazy/python-google-places
I am doing something like this:
from googleplaces import GooglePlaces, types, lang
API_KEY = ''
google_places = GooglePlaces(API_KEY)
query_result = google_places.nearby_search(
location='Mumbai', keyword='Restaurants',
radius=1000, types=[types.TYPE_RESTAURANT])
if query_result.has_attributions:
print query_result.html_attributions
for place in query_result.places:
print place.name
print place.geo_location
print place.place_id
Its given in the link itself. However , I keep getting the following error:
Traceback (most recent call last):
File "run.py", line 9, in <module>
radius=1000, types=[types.TYPE_RESTAURANT])
File "/home/neetu/Desktop/python-google-places/googleplaces/__init__.py", line 281, in nearby_search
lat_lng_str = self._generate_lat_lng_string(lat_lng, location)
File "/home/neetu/Desktop/python-google-places/googleplaces/__init__.py", line 593, in _generate_lat_lng_string
'lat_lng must be a dict with the keys, \'lat\' and \'lng\'. Cause: %s' % str(e))
ValueError: lat_lng must be a dict with the keys, 'lat' and 'lng'. Cause: Request to URL https://maps.googleapis.com/maps/api/geocode/json?sensor=false&key=AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI&address=Mumbai failed with response code: REQUEST_DENIED
Any help is super welcome :)
According to the documentation:
https://github.com/slimkrazy/python-google-places/blob/master/googleplaces/init.py:
You should be able to provide a location instead of a lat_lng pair, but you could try giving a lat_lng instead of a location.
Try removing:
location="Mumbai"
and adding
lat_lng={'lat:19.148320, 'lng':72.888794}
After digging through the code, I understand the error.
The error you got was:
ValueError: lat_lng must be a dict with the keys, 'lat' and 'lng'. Cause: >Request to URL https://maps.googleapis.com/maps/api/geocode/json?>sensor=false&key=AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI&address=Mumbai failed >with response code: REQUEST_DENIED
what it is saying is that it tried to look to google to get the lat_lng pair for "Mumbai", but the request failed as it was denied. Use a valid API key from Google and it should work.
I am reading a json file with dictionary and values, but I am battling to use a variable as a query item when searching the json file.
x = value_cloud = "%s%s%s" % (["L1_METADATA_FILE"],["IMAGE_ATTRIBUTES"],["CLOUD_COVER"])
for meta in filelist(dir):
with open (meta) as data_file:
data = json.load(data_file)
cloud = str(data[x])
The error I get is:
Traceback (most recent call last):
File "E:\SAMPLE\Sample_Script_AWS\L8_TOA_using_gdal_rasterio.py", line 96, in <module>
cloud = str(data[x])
KeyError: "['L1_METADATA_FILE']['IMAGE_ATTRIBUTES']['CLOUD_COVER']"
What I actually want is to search the json file for the key in the variable...
The keys do exist in the json file because when I run the following I get the correct output.
cloud = str(data["L1_METADATA_FILE"]["IMAGE_ATTRIBUTES"]["CLOUD_COVER"])
print cloud
My knowledge of python is sketchy, and I am passing the variable through as a string and not an expression or object and therefore it gives me that error. What is the correct way to create the variable and call the keys that I want.
Thanks in advance!
Your key ends up including the brackets in the string, which which where the error comes from. If you use each key in its own variable, like this:
x, y, z = "L1_METADATA_FILE", "IMAGE_ATTRIBUTES" , "CLOUD_COVER"
and then:
cloud = str(data[x][y][z])
it should avoid any errors.
I am facing issue with the Code which is framed with Class.
Basically before It was simply a file with functions defined in it.
So When I was trying to execute the file using command python filename.py, It is working fine as needed.
Code sample is as follows:
# Getting the tenant list
# Fetch the creation_date of tenant if exists
def get_tenants():
# Fetch tenant list
tenants_list = keystone.tenants.list()
# Fetch tenant ID
for tenant in tenants_list:
tenant_id = tenant.id
.
.
.
get_tenants()
So as shown in aboce code in the file I am trying to call get_tenants function, Also it is working fine as needed with no error.
Now I have Created the Class then moved all the functions in to the same.
Above function is Rewritten as follows now.
def get_tenants(self):
# Fetch tenant list
tenants_list = keystone.tenants.list()
# Fetch tenant ID
for tenant in tenants_list:
tenant_id = tenant.id
Then I have called the Function as follows:
billing = BillingEngine()
billing.get_tenants()
But, now I am getting the error as follows:
root#devstack:/opt/open-stack-tools/billing# python new_class.py
Traceback (most recent call last):
File "new_class.py", line 281, in <module>
BillingEngine().get_tenants()
File "new_class.py", line 75, in get_tenants
tenants_list = keystone.tenants.list()
NameError: global name 'keystone' is not defined
Note: Will provide the full file if needed.
May be you must define this?
class Example(object):
keystone = Keystone()
def get_tenants(self):
self.keystone.do_something()
I keep getting a FieldMissingError on a field ('severa_id') of which I am sure that it exists. I've checked ver_33.py which shows that the Exception triggers if the field is not in self._meta.fields.
table._meta.fields shows the field being there:
print(table._meta.fields)
>>>
['proj_code', 'severa_id', 'rec_id', 'ext_key']
>>>
This is the code I'm trying:
table = dbf.Table(path_to_dbf)
table.open()
for row in dbf.Process(table):
for project in projects:
if str(row.proj_code)[0:4] == project["ProjectNumber"]:
row.write_record(severa_id=project["GUID"])
I've also tried these methods of setting the field:
row.severa_id = project["ProjectNumber"]
#row.write()
row.write_record()
Lastly, I've also tried setting each of the other fields (with a random string) which results in the same error.
EDIT: I am using the dbf module (https://pypi.python.org/pypi/dbf/0.96.005)
EDIT: The original traceback:
Traceback (most recent call last):
File "<string>", line 420, in run_nodebug
File "C:\Users\Alexander\Documents\update_projecten\update_dbf.py", line 58, in <module>
row.write()
File "C:\Users\Alexander\Envs\vfp\lib\site-packages\dbf\ver_33.py", line 2451, in __getattr__
raise FieldMissingError(name)
dbf.ver_33.FieldMissingError: 'write: no such field in table'
EDIT: The final version of the script that worked. Note not using Process and indicating in dbf.write the row and field to be written.
table = dbf.Table(path_to_dbf)
table.open()
for row in table:
for project in projects:
if str(row.proj_code)[0:4] == project["ProjectNumber"]:
dbf.write(row, severa_id=project["GUID"])
write_record no longer exists as a row method, so the error you are seeing is probably stating that write_record is not a field.
Instead, try:
dbf.write(severa_id=project['GUID'])