I need to use the googlemaps/google-maps-services-python for a project, and there is the problem.
I want to use find_place():
def find_place(client, input, input_type, fields=None, location_bias=None,
language=None):
But when I launch my script
import googlemaps
from datetime import datetime
class Place:
def __init__(self, words):
self.words = words
self.key = 'Key'
self.gmaps = googlemaps.Client(key=self.key)
place = Place(['place to find'])
print(place.key)
loca = place.gmaps.find_place(self.key,"place to find","textquery",['place_id','formatted_address'])
print(loca)
there is a problem:
Traceback (most recent call last):
File "gpbapp/program/place.py", line 15, in <module>
loca = place.gmaps.find_place(place.key,place.words[0],"textquery",['place_id','formatted_address'])
File "C:\Users\krfou\Documents\OPENCLASSROOMS\p7\env\lib\site-packages\googlemaps\client.py", line 365, in wrapper
result = func(*args, **kwargs)
File "C:\Users\krfou\Documents\OPENCLASSROOMS\p7\env\lib\site-packages\googlemaps\places.py", line 94, in find_place
"the given value is invalid: '%s'" % input_type)
ValueError: Valid values for the `input_type` param for `find_place` are 'textquery' or 'phonenumber', the given value is invalid: 'disneyland, paris'
(env)
If I do
loca = place.gmaps.find_place(place.key,"textquery",['place_id','formatted_address'])
it works but I get no result (because input is not there anymore).
{'candidates': [], 'status': 'ZERO_RESULTS'}
There is a confusion between the positional arguments, as if there was a hidden argument ... what happens?
Won't it work if you do
loca = place.gmaps.find_place(client=place.key,input="place to find", input_type="textquery",fields=['place_id','formatted_address'])
Related
api = tweepy.API(auth)
userID_list = ["elonmusk", "BarackObama"]
for userxyz in userID_list:
user_info = api.get_user(userxyz)
name = user_info.name
description = user_info.description
location = user_info.name.location
followers_count = user_info.followers_count
friends_count = user_info.friends_count
Writes this Error:
Traceback (most recent call last):
File "C:/Users/wilsi/Desktop/test 123.py", line 36, in <module>
user_info = api.get_user(userxyz)
File "C:\Users\wilsi\Desktop\venv\lib\site-packages\tweepy\api.py", line 46, in wrapper
return method(*args, **kwargs)
TypeError: get_user() takes 1 positional argument but 2 were given
API.get_user only accepts a single user as a user_id or screen_name keyword argument.
See also the FAQ section in Tweepy's documentation about this.
For code block usage, see https://stackoverflow.com/editing-help.
i got error message when trying to run the test of django
this is my code for the model file
class MountPoint(models.Model):
name = models.CharField(max_length=100)
backend = models.CharField(max_length=200,default=DEFAULT_BACKEND)
path = models.CharField(max_length=300)
def __unicode__(self):
return self.name
and here is the class i put in test
class MountPoint(TestCase):
def create_mountpoint(self):
name = "test"
backend = "test"
path = user_root
return MountPoint(name, backend, path)
def test_mountpoint_creation(self):
m = self.create_mountpoint()
self.assertTrue(isinstance(m, MountPoint))
self.assertEqual(m.__unicode(), m.name)
and the error message i got is below. it said i have more inputs than expected.
Traceback (most recent call last):
File "/Users/xihui/Documents/WebProgramming/django/ece264site/filesystem/tests.py", line 18, in test_mountpoint_creation
m = self.create_mountpoint()
File "/Users/xihui/Documents/WebProgramming/django/ece264site/filesystem/tests.py", line 15, in create_mountpoint
return MountPoint(name, backend, path)
TypeError: init() takes at most 2 arguments (4 given)
Ran 1 test in 0.009s
FAILED (errors=1)
I think you must use keyword args:
return MountPoint(name=name, backend=backend, path=path)
lambda from getattr getting called with "connection" as a keyword argument? Am I misusing the code or is there a bug?
Code and traceback: https://github.com/bigcommerce/bigcommerce-api-python/issues/32
#!/usr/bin/env python2
import bigcommerce
import bigcommerce.api
BIG_URL = 'store-45eg5.mybigcommerce.com'
BIG_USER = 'henry'
BIG_KEY = '10f0f4f371f7953c4d7d7809b62463281f15c829'
api = bigcommerce.api.BigcommerceApi(host=BIG_URL, basic_auth=(BIG_USER, BIG_KEY))
def get_category_id(name):
get_request = api.Categories.get(name)
try:
cat_list = api.Categories.all(name=name)
if cat_list:
return cat_list[0]['id']
else:
return None
except:
return None
def create_category(name):
rp = api.Categories.create(name)
if rp.status == 201:
return rp.json()['id']
else:
return get_category_id(name)
create_category('anothertestingcat')
Gives this traceback:
Traceback (most recent call last):
File "./bigcommerceimporter.py", line 50, in
create_category('anothertestingcat')
File "./bigcommerceimporter.py", line 44, in create_category
rp = api.Categories.create(name)
File "/home/henry/big_test_zone/local/lib/python2.7/site-packages/bigcommerce/api.py", line 57, in
return lambda args, *kwargs: (getattr(self.resource_class, item))(args, connection=self.connection, *kwargs)
TypeError: create() got multiple values for keyword argument 'connection'
Line in api.py that the traceback refers to: https://github.com/bigcommerce/bigcommerce-api-python/blob/master/bigcommerce/api.py#L57
According to the examples, create should be used like this:
api.Categories.create(name = 'anothertestingcat')
Note: You should generate a new API KEY, since you published the current one in this question.
Anyone come across this before?
import boto
conn = boto.dynamodb.connect_to_region('eu-west-1', aws_access_key_id=aws_key, aws_secret_access_key=aws_secret)
table = conn.get_table('TweetSample')
print table.scan(limit=1)
error:
Traceback (most recent call last):
File "test.py", line 9, in <module>
print table.scan(limit=1)
File "table.py", line 518, in scan
return self.layer2.scan(self, *args, **kw)
TypeError: scan() got an unexpected keyword argument 'limit'
[Finished in 0.4s with exit code 1]
I don't even know...
According to the documentation, scan method of boto.dynamodb.table.Table (which is returned by boto.dynamodb.layer2.Layer2.get_table) does not accepts limit, but max_results.
And the result is a generator. So, if you want to print it you should iterate it:
import boto.dynamodb
conn = boto.dynamodb.connect_to_region(
'eu-west-1',
aws_access_key_id=aws_key,
aws_secret_access_key=aws_secret)
table = conn.get_table('TweetSample')
for row in table.scan(max_results=1):
print row
or convert it to a sequence:
print list(table.scan(max_results=1))
I've tried two different versions of the same function:
def position_of(self, table_name, column_name):
positions = self.heading_positions()
position = positions['{t}.{c}'.format(t=table_name, c=column_name)]
return position
-
def position_of(self, table_name, column_name):
positions = self.heading_positions()
try:
position = positions['{t}.{c}'.format(t=table_name, c=column_name)]
except KeyError:
raise RuntimeError('No heading found for {t}.{c} in import profile "{ip}"'.format(t=table_name, c=column_name, ip=self))
return position
With the first version, I get the following error, which is fine:
Traceback (most recent call last):
File "./import.py", line 15, in <module>
g.process()
File "/home/jason/projects/mcifdjango/mcif/models/generic_import.py", line 39, in process
row.process()
File "/home/jason/projects/mcifdjango/mcif/models/csv_row.py", line 18, in process
self.save()
File "/home/jason/projects/mcifdjango/mcif/models/csv_row.py", line 26, in save
self.output("Phone: " + self.value('customer', 'phone'));
File "/home/jason/projects/mcifdjango/mcif/models/csv_row.py", line 60, in value
print self.generic_import.import_profile.position_of(table_name, column_name)
File "/home/jason/projects/mcifdjango/mcif/models/import_profile.py", line 22, in position_of
position = positions['{t}.{c}'.format(t=table_name, c=column_name)]
KeyError: 'customer.phone'
But the second version - the one that has the more informative error description - fails silently. Why is this?
The second version of position_of works fine for me. I have turned it into a minimal complete program as follows:
class Test(object):
def heading_positions(self):
return {}
def position_of(self, table_name, column_name):
positions = self.heading_positions()
try:
position = positions['{t}.{c}'.format(t=table_name, c=column_name)]
except KeyError:
raise RuntimeError('No heading found for {t}.{c} in import profile "{ip}"'.format(t=table_name, c=column_name, ip=self))
return position
a = Test()
a.position_of('customer', 'phone')
When I run this (using Python 2.6.6 on MacOS X) I get the following error message as expected:
Traceback (most recent call last):
File "./a.py", line 17, in <module>
a.position_of('customer', 'phone')
File "./a.py", line 13, in position_of
raise RuntimeError('No heading found for {t}.{c} in import profile "{ip}"'.format(t=table_name, c=column_name, ip=self))
RuntimeError: No heading found for customer.phone in import profile "<__main__.Test object at 0x100426ad0>"
This shows that catching the KeyError and turning it into a RuntimeError works fine. Does this example work for you? As Sven already writes, a possible explanation would be if you catch RuntimeError but not KeyError somewhere in the call chain.