I am trying to retrieve all facebook posts by a user after a post id. When I do it, I get an unknown error.
my code:
from facebook import *
token = facebook.get_app_access_token('3291XXXXXXXXXXXXX','c498e60cb1eXXXXXXXXXXXXX')
graph = GraphAPI(token)
g = graph.get('travelguard/posts?limit=5&since=68827688457_10151569356908458')
>>> Traceback (most recent call last):
File "<pyshell#40>", line 1, in <module>
graph.get('travelguard/posts?limit=5&since=68827688457_10151569356908458')
File "C:\Documents and Settings\visolank\Desktop\Python\programs\facepy\graph_api.py", line 42, in get
retry=retry
File "C:\Documents and Settings\visolank\Desktop\Python\programs\facepy\graph_api.py", line 251, in _query
return self._query(method, path, data, page, retry - 1)
File "C:\Documents and Settings\visolank\Desktop\Python\programs\facepy\graph_api.py", line 251, in _query
return self._query(method, path, data, page, retry - 1)
File "C:\Documents and Settings\visolank\Desktop\Python\programs\facepy\graph_api.py", line 251, in _query
return self._query(method, path, data, page, retry - 1)
File "C:\Documents and Settings\visolank\Desktop\Python\programs\facepy\graph_api.py", line 248, in _query
return load(method, url, data)[0]
File "C:\Documents and Settings\visolank\Desktop\Python\programs\facepy\graph_api.py", line 210, in load
result = self._parse(response.content)
File "C:\Documents and Settings\visolank\Desktop\Python\programs\facepy\graph_api.py", line 290, in _parse
error.get('code', None)
OAuthError: [1] An unknown error has occurred.
Facebook's API doesn't have the best error messages. "An unknown error has occurred." means you don't have permissions to access what you're trying to access.
Related
I am trying to connect to Google Speech-to-Text API and keep bumping into this error. I'm a noob python user, so thanks in advance for your help and patience!
PS C:\Users\LUVU\Desktop\TD\twistcube\td_speech_to_text> python 2_speech_fromaudio.py
Traceback (most recent call last):
File "C:\Users\LUVU\Desktop\TD\twistcube\td_speech_to_text\2_speech_fromaudio.py", line 11, in <module>
client = speech.SpeechClient()
File "C:\Users\LUVU\AppData\Local\Programs\Python\Python310\lib\site-packages\google\cloud\speech_v1\services\speech\client.py", line 408, in __init__
self._transport = Transport(
File "C:\Users\LUVU\AppData\Local\Programs\Python\Python310\lib\site-packages\google\cloud\speech_v1\services\speech\transports\grpc.py", line 151, in __init__
super().__init__(
File "C:\Users\LUVU\AppData\Local\Programs\Python\Python310\lib\site-packages\google\cloud\speech_v1\services\speech\transports\base.py", line 105, in __init__
credentials, _ = google.auth.default(
File "C:\Users\LUVU\AppData\Local\Programs\Python\Python310\lib\site-packages\google\auth\_default.py", line 544, in default
credentials, project_id = checker()
File "C:\Users\LUVU\AppData\Local\Programs\Python\Python310\lib\site-packages\google\auth\_default.py", line 537, in <lambda>
lambda: _get_explicit_environ_credentials(quota_project_id=quota_project_id),
File "C:\Users\LUVU\AppData\Local\Programs\Python\Python310\lib\site-packages\google\auth\_default.py", line 218, in _get_explicit_environ_credentials
credentials, project_id = load_credentials_from_file(
File "C:\Users\LUVU\AppData\Local\Programs\Python\Python310\lib\site-packages\google\auth\_default.py", line 117, in load_credentials_from_file
raise exceptions.DefaultCredentialsError(
google.auth.exceptions.DefaultCredentialsError: File [td-cc-342823-bda3eb899dc0] was not found.
PS C:\Users\LUVU\Desktop\TD\twistcube\td_speech_to_text>
Screenshot
I've been following this (https://www.youtube.com/watch?v=cnPlKLEGR7E&list=PLdu6wGxXWFgX9XlahY9gHEMdZ7CL5CHMY&index=6) tutorial on using the google sheets API in python recently but have been met with the following error:
C:\Users\jadot\PycharmProjects\multiplicationTable\venv\Scripts\python.exe C:/Users/jadot/PycharmProjects/multiplicationTable/main.py
Traceback (most recent call last):
File "C:\Users\jadot\PycharmProjects\multiplicationTable\venv\lib\site-packages\google\oauth2\_client.py", line 196, in jwt_grant
access_token = response_data["access_token"]
KeyError: 'access_token'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\jadot\PycharmProjects\multiplicationTable\main.py", line 10, in <module>
sheet = client.open("multiplicationTable").sheet1
File "C:\Users\jadot\PycharmProjects\multiplicationTable\venv\lib\site-packages\gspread\client.py", line 122, in open
self.list_spreadsheet_files(title),
File "C:\Users\jadot\PycharmProjects\multiplicationTable\venv\lib\site-packages\gspread\client.py", line 99, in list_spreadsheet_files
res = self.request('get', url, params=params).json()
File "C:\Users\jadot\PycharmProjects\multiplicationTable\venv\lib\site-packages\gspread\client.py", line 64, in request
response = getattr(self.session, method)(
File "C:\Users\jadot\PycharmProjects\multiplicationTable\venv\lib\site-packages\requests\sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "C:\Users\jadot\PycharmProjects\multiplicationTable\venv\lib\site-packages\google\auth\transport\requests.py", line 476, in request
self.credentials.before_request(auth_request, method, url, request_headers)
File "C:\Users\jadot\PycharmProjects\multiplicationTable\venv\lib\site-packages\google\auth\credentials.py", line 133, in before_request
self.refresh(request)
File "C:\Users\jadot\PycharmProjects\multiplicationTable\venv\lib\site-packages\google\oauth2\service_account.py", line 410, in refresh
access_token, expiry, _ = _client.jwt_grant(
File "C:\Users\jadot\PycharmProjects\multiplicationTable\venv\lib\site-packages\google\oauth2\_client.py", line 199, in jwt_grant
six.raise_from(new_exc, caught_exc)
File "<string>", line 3, in raise_from
google.auth.exceptions.RefreshError: ('No access token in response.', {'id_token': 'eyJhbGciOiJSUzI1NiIsImtpZCI6ImQ0ZTA2Y2ViMjJiMDFiZTU2YzIxM2M5ODU0MGFiNTYzYmZmNWE1OGMiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwczovL3NwcmVhZHNoZWV0cy5nb29nbGUuY29tL2ZlZWRzLGh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvc3ByZWFkaGVldHMsaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vYXV0aC9kcml2ZS5maWxlLGh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvZHJpdmUiLCJhenAiOiJqYWRvLTI1OEBtdWx0aXBsaWNhdGlvbi1jaGFydC0zMzMxMDEuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJlbWFpbCI6ImphZG8tMjU4QG11bHRpcGxpY2F0aW9uLWNoYXJ0LTMzMzEwMS5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJleHAiOjE2Mzc3OTE4OTUsImlhdCI6MTYzNzc4ODI5NSwiaXNzIjoiaHR0cHM6Ly9hY2NvdW50cy5nb29nbGUuY29tIiwic3ViIjoiMTA4NjQ2MDgzNzQ4MzU3Mzc2NzMxIn0.TEjhypfcTum53KYhiQkrRSCXAOna2poZAAGMUorMJiXP6en89ETDRrcrbxYHX6FMKTmWANyG-H9Fg3xUq6FnB-uLQQkRmEgw0r2K6meCJa97sPhoU0khRAwvbLesMFLO8mOBMJ7NzJythmdi8XFMc9LajthtkUZ4Ko_QfHBdPMK9iv90qAPyrmQsl1rTh6yycfvYrUFExpogsBc0Ax3vfwyjohiywQ3YenQBmgNYuE7QBtUvVgG_yGkDZI40QBK9nO_oJqDhvO_QhsH-42g5X26dBDkerWzZ0DikGTeMgPCFSGBmv0Cd2rKyLQL5JcYJNHEKAHgVVs__SFB_OWha3Q'})
Process finished with exit code 1
This is my code:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("C:/Users/jadot/PycharmProjects/multiplicationTable/creds.json", scope)
client = gspread.authorize(creds)
sheet = client.open("multiplicationTable").sheet1
There are several similar cases on stack overflow, all of which I've tried with no avail.
Trying to set up static assets on a Pyramid app. I used the following call:
config.add_static_view(name='static', path='toolsofknowledge:static')
The file main.css is stored under toolsofknowledge/static/main.css, as expected. The toolsofknowledge package is installed locally with an editable link, using pip3 install -e ..
Requesting http://localhost:8080/static/main.css with curl causes this exception on the server:
amoe#cslp019129 $ PYRAMID_RELOAD_TEMPLATES=1 pserve3 --reload development.ini
Starting monitor for PID 3796.
Starting server in PID 3796.
Serving on http://localhost:8080
Serving on http://localhost:8080
ERROR:waitress:Exception when serving /static/main.css
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pyramid/tweens.py", line 13, in _error_handler
response = request.invoke_exception_view(exc_info)
File "/usr/lib/python3/dist-packages/pyramid/view.py", line 769, in invoke_exception_view
raise HTTPNotFound
pyramid.httpexceptions.HTTPNotFound: The resource could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/waitress/channel.py", line 336, in service
task.service()
File "/usr/lib/python3/dist-packages/waitress/task.py", line 175, in service
self.execute()
File "/usr/lib/python3/dist-packages/waitress/task.py", line 452, in execute
app_iter = self.channel.server.application(env, start_response)
File "/usr/lib/python3/dist-packages/pyramid/router.py", line 270, in __call__
response = self.execution_policy(environ, self)
File "/usr/lib/python3/dist-packages/pyramid/router.py", line 279, in default_execution_policy
return request.invoke_exception_view(reraise=True)
File "/usr/lib/python3/dist-packages/pyramid/view.py", line 768, in invoke_exception_view
reraise_(*exc_info)
File "/usr/lib/python3/dist-packages/pyramid/compat.py", line 179, in reraise
raise value
File "/usr/lib/python3/dist-packages/pyramid/router.py", line 277, in default_execution_policy
return router.invoke_request(request)
File "/usr/lib/python3/dist-packages/pyramid/router.py", line 249, in invoke_request
response = handle_request(request)
File "/usr/lib/python3/dist-packages/pyramid/tweens.py", line 43, in excview_tween
response = _error_handler(request, exc)
File "/usr/lib/python3/dist-packages/pyramid/tweens.py", line 17, in _error_handler
reraise(*exc_info)
File "/usr/lib/python3/dist-packages/pyramid/compat.py", line 179, in reraise
raise value
File "/usr/lib/python3/dist-packages/pyramid/tweens.py", line 41, in excview_tween
response = handler(request)
File "/usr/lib/python3/dist-packages/pyramid/router.py", line 148, in handle_request
registry, request, context, context_iface, view_name
File "/usr/lib/python3/dist-packages/pyramid/view.py", line 657, in _call_view
response = view_callable(context, request)
File "/usr/lib/python3/dist-packages/pyramid/viewderivers.py", line 401, in viewresult_to_response
result = view(context, request)
File "/usr/lib/python3/dist-packages/pyramid/static.py", line 102, in __call__
if resource_isdir(self.package_name, resource_path):
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1138, in resource_isdir
return get_provider(package_or_requirement).resource_isdir(
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 364, in get_provider
return _find_adapter(_provider_factories, loader)(module)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1392, in __init__
self.module_path = os.path.dirname(getattr(module, '__file__', ''))
File "/usr/lib/python3.7/posixpath.py", line 156, in dirname
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
Python 3.7, Pyramid 1.10.2.
Solution: add __init__.py to toolsofknowledge directory.
The problem is quite simple -- the toolsofknowledge package was not a real package, despite being installed, as it was missing an __init__.py. This causes toolsofknowledge.__loader__ to be an instance of NamespaceLoader, when it should be SourceFileLoader. Obviously, pkg_resources cannot resolve resources relative to something that's not a real package. Arguably it should handle this case more smoothly though.
I'm using SOPApy to make a client for SOAP. Following code rises error.
import SOAPpy
wsdlFile = 'https://10.10.10.10/services/fwif?wsdl'
proxy = SOAPpy.WSDL.Proxy(wsdlFile)
Traceback (most recent call last):
File "run.py", line 28, in <module>
proxy = SOAPpy.WSDL.Proxy(wsdlFile)
File "/home/dinn/miniconda/envs/soaptest/lib/python2.7/site-packages/SOAPpy/WSDL.py", line 83, in __init__
self.wsdl = reader.loadFromString(str(wsdlsource))
File "/home/dinn/miniconda/envs/soaptest/lib/python2.7/site-packages/wstools/WSDLTools.py", line 49, in loadFromString
return self.loadFromStream(StringIO(data))
File "/home/dinn/miniconda/envs/soaptest/lib/python2.7/site-packages/wstools/WSDLTools.py", line 28, in loadFromStream
document = DOM.loadDocument(stream)
File "/home/dinn/miniconda/envs/soaptest/lib/python2.7/site-packages/wstools/Utility.py", line 645, in loadDocument
return xml.dom.minidom.parse(data)
File "/home/dinn/miniconda/envs/soaptest/lib/python2.7/xml/dom/minidom.py", line 1918, in parse
return expatbuilder.parse(file)
File "/home/dinn/miniconda/envs/soaptest/lib/python2.7/xml/dom/expatbuilder.py", line 928, in parse
result = builder.parseFile(file)
File "/home/dinn/miniconda/envs/soaptest/lib/python2.7/xml/dom/expatbuilder.py", line 207, in parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 6
On stackoverflow I found a similar problem When I consume wsdl using python, I get an xml.parsers.expat.ExpatError but don't understand how to apply it for SOAPpy.
I Use the following code to use a soap webservice written in PHP
#!/usr/local/bin/python
import logging
logging.basicConfig(levee = logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
import urllib2
from suds.client import Client
from suds.sax.element import Element
url = 'a sopa webservice url'
client = Client(url)
It comes out the following error:
Traceback (most recent call last):
File "./auth.py", line 13, in <module>
client = Client(url)
File "build/bdist.linux-x86_64/egg/suds/client.py", line 112, in __init__
File "build/bdist.linux-x86_64/egg/suds/reader.py", line 152, in open
File "build/bdist.linux-x86_64/egg/suds/wsdl.py", line 136, in __init__
File "build/bdist.linux-x86_64/egg/suds/reader.py", line 79, in open
File "build/bdist.linux-x86_64/egg/suds/reader.py", line 101, in download
File "build/bdist.linux-x86_64/egg/suds/sax/parser.py", line 136, in parse
File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "/usr/local/lib/python2.7/xml/sax/xmlreader.py", line 125, in parse
self.close()
File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 220, in close
self.feed("", isFinal = 1)
File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 214, in feed
self._err_handler.fatalError(exc)
File "/usr/local/lib/python2.7/xml/sax/handler.py", line 38, in fatalError
raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:0: no element found
I'm new to suds and sopa webservice,I don't know what the error means, can someone can give me some advices
You'll need this line to debug that:
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
Sample output:
DEBUG:suds.transport.http:received:
CODE: 200
HEADERS: {'content-length': '16', ..., 'connection': 'close', 'x-sharepointhealthscore': '0', 'cache-control': 'private, max-age=0', 'date': 'Tue, 25 Mar 2014 11:24:51 GMT', 'www-authenticate': 'NTLM'}
MESSAGE:
401 UNAUTHORIZED
DEBUG:suds.client:HTTP succeeded:
401 UNAUTHORIZED
ERROR:suds.client:<suds.sax.document.Document instance at 0x02C21AF8>
Traceback (most recent call last):
File "ExpiryMonitor.py", line 99, in <module>
if __name__ == '__main__': main()
File "ExpiryMonitor.py", line 66, in main
items = c_lists.service.GetListItems(LIST_ID, VIEW_ID)
File "build\bdist.win32\egg\suds\client.py", line 521, in __call__
File "build\bdist.win32\egg\suds\client.py", line 581, in invoke
File "build\bdist.win32\egg\suds\client.py", line 621, in send
File "build\bdist.win32\egg\suds\client.py", line 661, in process_reply
File "build\bdist.win32\egg\suds\client.py", line 832, in _parse
File "build\bdist.win32\egg\suds\sax\parser.py", line 133, in parse
File "C:\python27\lib\xml\sax\expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "C:\python27\lib\xml\sax\xmlreader.py", line 123, in parse
self.feed(buffer)
File "C:\python27\lib\xml\sax\expatreader.py", line 211, in feed
self._err_handler.fatalError(exc)
File "C:\python27\lib\xml\sax\handler.py", line 38, in fatalError
raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:0: syntax error
Apparently even the maintained suds-jurko fork doesn't throw an error when using a login with insufficient rights.
Typically, this means the server is returning data, but it is not valid XML. It's likely a server problem.