Google People API: reading "other contacts" with addresses - google-api

I need to read addresses of "other contacts". Docs say that in order to do this, READ_SOURCE_TYPE_PROFILE should be set. However, when doing it like this:
service = googleapiclient.discovery.build('people', 'v1', credentials=credentials)
resource = service.otherContacts()
request = resource.list(
readMask='names,emailAddresses,phoneNumbers,addresses',
sources='READ_SOURCE_TYPE_PROFILE',
pageSize=1000
)
request.execute()
... I am getting the following error: Must request READ_SOURCE_TYPE_CONTACT. Full traceback:
Traceback (most recent call last):
File "C:\Users\Leo\workspace\gapitest\main.py", line 22, in <module>
response = request.execute()
File "C:\Users\Leo\workspace\gapitest\venv\lib\site-packages\googleapiclient\_helpers.py", line 131, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\Leo\workspace\gapitest\venv\lib\site-packages\googleapiclient\http.py", line 937, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://people.googleapis.com/v1/otherContacts?readMask=names%2CemailAddresses%2CphoneNumbers&sources=READ_SOURCE_TYPE_PROFILE&pageSize=1000&alt=json returned "Must request READ_SOURCE_TYPE_CONTACT". Details: "Must request READ_SOURCE_TYPE_CONTACT">
What am I doing wrong?

It seems that what you are seeing might be a bug.
I have filed this issue on Issue Tracker here so feel free to star it and eventually add a comment, as any updates shall be posted there.

According to Google's documentation:
Specifying READ_SOURCE_TYPE_PROFILE without specifying READ_SOURCE_TYPE_CONTACT is not permitted.
Setting both READ_SOURCE_TYPE_CONTACT and READ_SOURCE_TYPE_PROFILE should resolve this issue.

Related

h2o hit_ratio_table AttributeError

I'm following a tutorial from https://github.com/h2oai/h2o-tutorials/blob/master/tutorials/gbm-randomforest/GBM_RandomForest_Example.py
I have been following the tutorial until I reached the line with hit_ratio_table. when I executed
"rf_v1.hit_ratio_table(valid=True)", I encounter the error below.
>>> rf_v1.hit_ratio_table(valid=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/h2oUser/sparkling-water-2.3.0/py/build/dist/h2o_pysparkling_2.3-2.3.0.zip/h2o/utils/backward_compatibility.py", line 74, in __getattr__
File "/home/h2oUser/sparkling-water-2.3.0/py/build/dist/h2o_pysparkling_2.3-2.3.0.zip/h2o/utils/backward_compatibility.py", line 49, in __getattribute__
AttributeError: type object 'H2ORandomForestEstimator' has no attribute 'hit_ratio_table'
I tried to search if hit_ratio_table is being deprecated or not, but I can't find any links. Does anyone know if this function has been changed?
The attribute is still there, it looks like the tutorial is missing a line of code right after the file import, which means the model is being considered as a regression problem instead of a classification problem. So if you add the following line after you import the covtype dataset:
covtype_df[54] = covtype_df[54].asfactor()
which converts the target to a factor, it should work.
If you want to play around with the hit_ratio_table() you can look at this code snippet in the H2O-3 user guide.

Getting permissions exception when calling amazondax service

I'm using the amazondax service from an AWS Lambda method, and getting an exception that indicates missing permissions - but I don't know what permissions are necessary for this. Both the Lambda method and my DAX cluster are setup with the same VPC subnets and security groups. I'm getting the following exception:
[ERROR] 2018-12-11T23:06:50.457Z 70c80374-fd99-11e8-bac1-318371e7b8ed Failed to retrieve endpoints
Traceback (most recent call last):
File "/var/task/amazondax/Cluster.py", line 211, in _pull
new_endpoints = self._pull_from(ip, port)
File "/var/task/amazondax/Cluster.py", line 222, in _pull_from
endpoints = client.endpoints()
File "/var/task/amazondax/DaxClient.py", line 192, in endpoints
return self._decode_result('endpoints', None, Assemblers.endpoints_455855874_1, tube)
File "/var/task/amazondax/DaxClient.py", line 227, in _decode_result
return self._handle_error(operation_name, tube)
File "/var/task/amazondax/DaxClient.py", line 233, in _handle_error
raise DaxServiceError(operation_name, message, codes, *exc_info)
amazondax.DaxError.DaxServiceError: An error occurred (Unknown) when calling the endpoints operation: Client does not have permission to invoke Endpoints
I assume the last line "Client does not have permission..." is the key to this, but I'm having trouble figuring out exactly what permission(s) are required.
Here is the code that is breaking:
dax = amazondax.AmazonDaxClient(session, region_name='us-east-1', endpoint_url='mydaxcluster.blahblahblah.cache.amazonaws.com:8111')
You will need to add "dax:" permissions for the operations you need to the policy associated with the IAM user used in the session.

Python : bad handshake error on get request when executed on windows but not linux

I'm wrote a python script to download the content of a website and it is working perfectly fine when i execute it on a linux machine, but not on windows (and it needs to be executed on windows).
Here is the code generating the error :
import requests
c = requests.Session()
url = 'https://ted.jeancoutu.com/action/login'
c.get(url)
Here is the error message i get when i execute the code on a windows machine:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\packages\urllib3\contrib\pyopenssl.py", line 348, in ssl_wrap_socket
cnx.do_handshake()
File "C:\Python34\lib\site-packages\OpenSSL\SSL.py", line 1443, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "C:\Python34\lib\site-packages\OpenSSL\SSL.py", line 1191, in _raise_ssl_error
_raise_current_error()
File "C:\Python34\lib\site-packages\OpenSSL\_util.py", line 48, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 578, in urlopen
chunked=chunked)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 351, in _make_request
self._validate_conn(conn)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 814, in _validate_conn
conn.connect()
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 289, in connect
ssl_version=resolved_ssl_version)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\contrib\pyopenssl.py", line 355, in ssl_wrap_socket
raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')],)",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\adapters.py", line 403, in send
timeout=timeout
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 604, in urlopen
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')],)",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\requests\sessions.py", line 487, in get
return self.request('GET', url, **kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 585, in send
r = adapter.send(request, **kwargs)
File "C:\Python34\lib\site-packages\requests\adapters.py", line 477, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')],)",)
I couldn't find a solution to this problem. I tried many suggestions i found online but nothing worked. I installed pyOpenSSL, ndg-httpsclient and pyasn1 with no result. I also upgraded ssl but still nothing.
Thank you for your suggestions
The site ted.jeancoutu.com only supports RC4-SHA and RC4-MD5 ciphers (see SSLLabs report. RC4 ciphers are considered insecure and therefore got removed from the default cipher set in requests in version 2.5.2 in 02/2015. You are probably using an older version of requests on Linux so it still works, but it fails with the newer version on Windows.
See https://stackoverflow.com/a/32651967/3081018 for how to work around the problem by enabling the insecure cipher.

nginx + python app -- how to enable error logging/stack trace

I have a Flask app running on nginx + uWSGI.
On my local server (non-nginx), I get a nice stack trace + error reporting for exceptions.
Like this:
$ python run.py
Traceback (most recent call last):
File "run.py", line 1, in <module>
from myappname import app
File "/home/me/myappname/myappname/__init__.py", line 27, in <module>
file_handler.setLevel(logging.debug)
File "/usr/lib/python2.7/logging/__init__.py", line 710, in setLevel
self.level = _checkLevel(level)
File "/usr/lib/python2.7/logging/__init__.py", line 190, in _checkLevel
raise TypeError("Level not an integer or a valid string: %r" % level)
On nginx, there is next to no logging whatsoever (in /var/log/nginx/error.log).
This post suggests adding app.logger.exception('Failed') to my script, which didn't help.
How do I enable this sort of logging for debugging purposes?
Nginx will capture your app's console output, but you must make the app recover from exceptions. Else, you'll only get 500 or 400 errors from Nginx.
Try running the app off Nginx until it seems stable.
Use the logging module to capture app status information to your own log file. This strategy will be useful in the long run.

Django on IIS with Multiple Sites: How To Make ISAPI.py Cooperate

Python 2.6.2 / Django 1.0.2 on Win 2003 Standard IIS 6.
IIs is running two django sites with the following directory structure:
root/http/WEBSITE1
root/http/WEBSITE2
Both sites have their own application pools; each site has it's own pyISAPIe.dll instance.
WEBSITE1 is accessible (serving test django page). However, the browser produces the following for WEBSITE2:
Internal Server Error
An error occurred processing this request.
Request handler failed
Traceback (most recent call last):
File "D:\Python26\lib\site-packages\Http\Isapi.py", line 67, in Request
return RunWSGI(Handler, Base=Base)
File "D:\Python26\lib\site-packages\Http\WSGI.py", line 155, in RunWSGI
Result = Application(Environ, StartResponse)
File "D:\Python26\lib\site-packages\django\core\handlers\wsgi.py", line 241, in call
response = self.get_response(request)
File "D:\Python26\lib\site-packages\django\core\handlers\base.py", line 122, in get_response
return self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "D:\Python26\lib\site-packages\django\core\handlers\base.py", line 166, in handle_uncaught_exception
return callback(request, **param_dict)
File "D:\Python26\lib\site-packages\django\views\defaults.py", line 23, in server_error
t = loader.get_template(template_name) # You need to create a 500.html template.
File "D:\Python26\lib\site-packages\django\template\loader.py", line 81, in get_template
source, origin = find_template_source(template_name)
File "D:\Python26\lib\site-packages\django\template\loader.py", line 74, in find_template_source
raise TemplateDoesNotExist, name
django.template.TemplateDoesNotExist: 500.html
It seems to me that "Isapi.py" located in root/pytho26/Lib/site-packages/Http has everything to do with this because of the "os.environ["DJANGO_SETTINGS_MODULE"] = "WEBSITE1.settings"
How can I modify this file or position it so that both sites run independently.
For anyone interested, the solution lies here
http://groups.google.com/group/pyisapie/browse_thread/thread/b67e861c85e1b26a
Follow option #3 to the letter and you will be able to run multiple IIS sites.

Resources