I recently decided to quickly re-setup google identity toolkit using a new application, which I thought would be a walk in the park until I became stranded on the 401 Unauthorized error below...
To make sure this was a clean setup, I followed the step-by-step setup instructions exactly (https://developers.google.com/identity/toolkit/web/configure-service) including the step of converting the .p12 file to .pem with openssl pkcs12 -in xxxxx.p12 -nodes -nocerts > privatekey.pem
As a side note, I previously had this up and running perfectly a couple of months back and can't seem to identify the error this time round.. Thought it must be the .pem file so I tried using the .p12 and even the .json rsa file but I'm guessing gitkit still can't accept those options
Any ideas?
HTTP Error 401: Unauthorized Traceback (most recent call last): File
"/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py",
line 1529, in call
rv = self.router.dispatch(request, response) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py",
line 1278, in default_dispatcher
return route.handler_adapter(request, response) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py",
line 1101, in call
handler = self.handler(request, response) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py",
line 528, in init
self.initialize(request, response) File "/base/data/home/apps/s~[site]/1.391420460413032384/main.py",
line 56, in initialize
gitkit_user = gitkit_instance.VerifyGitkitToken(self.request.cookies['gtoken'])
File
"/base/data/home/apps/s~[site]/1.391420460413032384/lib/identitytoolkit/gitkitclient.py",
line 216, in VerifyGitkitToken
certs = self.rpc_helper.GetPublicCert() File "/base/data/home/apps/s~[site]/1.391420460413032384/lib/identitytoolkit/rpchelper.py",
line 157, in GetPublicCert
headers = {'Authorization': 'Bearer ' + self._GetAccessToken()} File
"/base/data/home/apps/s~[site]/1.391420460413032384/lib/identitytoolkit/rpchelper.py",
line 207, in _GetAccessToken
raw_response = urllib2.urlopen(req, body) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py",
line 127, in urlopen
return _opener.open(url, data, timeout) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py",
line 410, in open
response = meth(req, response) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py",
line 523, in http_response
'http', request, response, code, msg, hdrs) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py",
line 448, in error
return self._call_chain(*args) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py",
line 382, in _call_chain
result = func(*args) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py",
line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 401: Unauthorized
Ok, have figured it out.. Looks like needed to update the gitkit client to the version from Dec 2015 (was using Sep 2015), which no longer needs the conversion from .p12 to .pem
Related
I am using the python-eureka-client to register my Python service with Eureka and send and receive REST calls.
I sometimes get the error shown below when my Python service is under very heavy load. The service tries to send back its result to another service using this command:
res = eureka_client.do_service(
app_name=SCIARA_EMISSIONS_SERVICE,
service='/some-address/',
method="PUT",
headers={'Content-Type': 'application/json', 'Authorization': jwt_id_token},
data=json_term.encode("utf-8"),
timeout=10
)
this usually works, but every once in a while it throws the error below. I already tried increasing the timeout to no avail.
Do you have any other suggestions as to what may be going on?
Thanks, Tim
Versions:
Python 3.9.6
py_eureka_client==0.11.3
spring-config-client==0.2
Error listing:
Traceback (most recent call last):
File "/usr/src/app/api.py", line 43, in send_result
res = eureka_client.do_service(
File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 1310, in do_service
return get_event_loop().run_until_complete(do_service_async(app_name=app_name, service=service, return_type=return_type,
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 1180, in do_service_async
res = await cli.do_service(app_name=app_name, service=service, return_type=return_type,
File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 937, in do_service
return await self.walk_nodes(app_name, service, prefer_ip, prefer_https, walk_using_urllib)
File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 894, in walk_nodes
return await obj
File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 929, in walk_using_urllib
res: http_client.HttpResponse = await http_client.http_client.urlopen(
File "/usr/local/lib/python3.9/site-packages/py_eureka_client/http_client.py", line 148, in urlopen
res = urllib.request.urlopen(req._to_urllib_request(), data=data, timeout=timeout)
File "/usr/local/lib/python3.9/urllib/request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.9/urllib/request.py", line 523, in open
response = meth(req, response)
File "/usr/local/lib/python3.9/urllib/request.py", line 632, in http_response
response = self.parent.error(
File "/usr/local/lib/python3.9/urllib/request.py", line 561, in error
return self._call_chain(*args)
File "/usr/local/lib/python3.9/urllib/request.py", line 494, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.9/urllib/request.py", line 641, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Unauthorized
I'm using Django and i'm trying to run this lib 'translate' or 'goslate' so I can translate text from google translate in runtime and free.
for goslate:
this is my function
import goslate
gs = goslate.Goslate()
translate = gs.translate(txt,target,source)
when I work locally it's working great and I'm getting the translation for the given 'txt'
I deploy my django app to herokuapp.com I got an error
this is the error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/app/.heroku/python/lib/python2.7/site-packages/goslate.py", line 409, in translate
return _unwrapper_single_element(self._translate_single_text(text, target_language, source_language))
File "/app/.heroku/python/lib/python2.7/site-packages/goslate.py", line 334, in _translate_single_text
results = list(self._execute(make_task(i) for i in split_text(text)))
File "/app/.heroku/python/lib/python2.7/site-packages/goslate.py", line 203, in _execute
yield each()
File "/app/.heroku/python/lib/python2.7/site-packages/goslate.py", line 332, in <lambda>
return lambda: self._basic_translate(text, target_language, source_lauguage)[0]
File "/app/.heroku/python/lib/python2.7/site-packages/goslate.py", line 251, in _basic_translate
response_content = self._open_url(url)
File "/app/.heroku/python/lib/python2.7/site-packages/goslate.py", line 181, in _open_url
response = self._opener.open(request, timeout=self._TIMEOUT)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 437, in open
response = meth(req, response)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 469, in error
result = self._call_chain(*args)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 656, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 437, in open
response = meth(req, response)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 475, in error
return self._call_chain(*args)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/app/.heroku/python/lib/python2.7/urllib2.py", line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 503: Service Unavailable
why locally it's working great and on heroku it's not? how can I fix it?
or a new translation lib that it's free
I found the problem,
google translate block the request from heroku
i need to use proxy server so google translate will not think that i'm a robot
there is an free app that i found in heroku named "fixie" i think it will do the trick
I am extremely new to XML and have what I hope is a simple question. I am trying to open an XML file at a location given to me by the BBC. If I click on the link using Firefox sure enough I get a page of XML.
But using Python 2.7.6 under Ubuntu 14.04 if I attempt the following fragment of code
import urllib2
xmldoc="http://www.bbc.co.uk/iplayer/ion/schedule/date/2014-09-10/masterbrand/bbc_radio_four/"
u = urllib2.urlopen(xmldoc)
I get:
Traceback (most recent call last):
File "/home/tim/metatron/Projects/R4/tp.py", line 7, in <module>
u = urllib2.urlopen(xmldoc)
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 406: Not Acceptable
I've never come across a 406 error before. I would note that the URI I have ben given by the BBC differs from others which usually end .../something.xml.
What am I doing wrong? Specifically why can Firefox open the file but not Python? IS there some sort of default xml file which would be loaded (analogous to index.html)
Similarly if I do a root=lxml.etree.parse(xmldoc) I get
Traceback (most recent call last):
File "/home/tim/metatron/Projects/R4/tp.py", line 8, in <module>
root=lxml.etree.parse(xmldoc)
File "lxml.etree.pyx", line 3239, in lxml.etree.parse (src/lxml/lxml.etree.c:69955)
File "parser.pxi", line 1748, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:102066)
File "parser.pxi", line 1774, in lxml.etree._parseDocumentFromURL (src/lxml/lxml.etree.c:102\330)
File "parser.pxi", line 1678, in lxml.etree._parseDocFromFile (src/lxml/lxml.etree.c:101365)
File "parser.pxi", line 1110, in lxml.etree._BaseParser._parseDocFromFile (src/lxml/lxml.etr\
ee.c:96817)
File "parser.pxi", line 582, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lx\
ml.etree.c:91275)
File "parser.pxi", line 683, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:92461)
File "parser.pxi", line 620, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:91722)
IOError: Error reading file 'http://www.bbc.co.uk/iplayer/ion/schedule/date/2014-09-10/masterb\
rand/bbc_radio_four/': failed to load HTTP resource
There is some info on HTTP 406 response code here, but basically, the BBC server is sensitive to the Accept HTTP header which is not automatically set by urllib2.urlopen().
Firefox will set this header to accept most anything - in mine it sets Accept to:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
but Accept: application/xml would seem sufficient in this case.
You can set the header like this:
import urllib2
request = urllib2.Request('http://www.bbc.co.uk/iplayer/ion/schedule/date/2014-09-10/masterbrand/bbc_radio_four/',
headers={'Accept': 'application/xml'})
response = urllib2.urlopen(request)
>>> print response.getcode()
200
>>> print response.read()[:100]
<?xml version="1.0" encoding="utf-8"?>\n<ion xmlns="http://bbc.co.uk/2008/iplayer/ion">\n <blocklist>
I recommend that you look at using the requests module - it simplifies this to a one-liner:
import requests
response = requests.get('http://www.bbc.co.uk/iplayer/ion/schedule/date/2014-09-10/masterbrand/bbc_radio_four/',
headers={'Accept': 'application/xml'})
When I setup, I get:
C:\Python27>python Lib\site-packages\rdflib-master\setup.py
Traceback (most recent call last):
File "Lib\site-packages\rdflib-master\setup.py", line 64, in <module>
version = find_version('rdflib/__init__.py')
File "Lib\site-packages\rdflib-master\setup.py", line 59, in find_version
for line in open(filename):
IOError: [Errno 2] No such file or directory: 'rdflib/__init__.py'
The file is there, and I've tried adding the package path to PYTHONPATH; no luck.
So I tried using ez_setup.py, but that chokes on some url that gives it a 404 (trace below).
I've also searched for general installation advice: I find pre-K and postgrad, but nothing that helps me.
Downloading http://cheeseshop.python.org/packages/2.7/s/setuptools/setuptools-0.6c5-py2.7.egg
Traceback (most recent call last):
File "Lib\site-packages\rdflib-master\ez_setup.py", line 223, in <module>
main(sys.argv[1:])
File "Lib\site-packages\rdflib-master\ez_setup.py", line 155, in main
egg = download_setuptools(version, delay=0)
File "Lib\site-packages\rdflib-master\ez_setup.py", line 137, in download_setuptools
src = urllib2.urlopen(url)
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 400, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 513, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 432, in error
result = self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 372, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 619, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\Python27\lib\urllib2.py", line 400, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 513, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 438, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 372, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 521, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
We need a bit more info I am afraid. Which version of RDFLib? How are trying to install?
Can we have the full error message?
The best way is to use "pip", install it somehow: http://www.pip-installer.org/en/1.3.X/installing.html
and then do
pip install rdflib
This will install the newest RDFLib 3.2.X!
It's a strange idea to put the source into Lib\site-packages but if you want to install from sources you need to call setup.py from the source directory. It complains that rdflib/__init__.py doesn't exist because it doesn't exist: note that the path is relative.
I have completed a program that is outlined in chapter 3 of Head First Programming.
Basically, the program searches a website and stores the price on that page. Then depending on which option the user selects, a certain message will be sent to the user's twitter account.
Source code from book's website: http://headfirstlabs.com/books/hfprog/chapter03/page108.py
When I run my program, and run the source code from the book's website, I get the same error.
Here is the error:
Traceback (most recent call last):
File "C:\Users\Krysten\Desktop\Ch3.py", line 28, in <module>
send_to_twitter(get_price())
File "C:\Users\Krysten\Desktop\Ch3.py", line 14, in send_to_twitter
resp = urllib.request.urlopen("http://twitter.com/statuses/update.json", params)
File "C:\Python31\lib\urllib\request.py", line 121, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python31\lib\urllib\request.py", line 356, in open
response = meth(req, response)
File "C:\Python31\lib\urllib\request.py", line 468, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python31\lib\urllib\request.py", line 394, in error
return self._call_chain(*args)
File "C:\Python31\lib\urllib\request.py", line 328, in _call_chain
result = func(*args)
File "C:\Python31\lib\urllib\request.py", line 476, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Unauthorized
Is the error being caused because the book is somewhat outdated and twitter has to be accessed in a different way?
In most of Twitter API, basic authentication is deprecated. Use OAuth API.