How to get the content of "Google Dictionary" by python script - python

Thank to the script, I've logged in google successfully.
But I replaced the value of "gv_home_page_url" with http:// www.google.com.tw/dictionary/wordlist?hl=zh-TW, the error occured.
The message is "
urllib2.HTTPError: HTTP Error 500: Internal Server Error"
Any idea will be appreciated, thanks.

That's not a valid URL. If you try to enter it in your bar, you'll get redirected to Google search results. Using urllib2, you'll get an error.
See here for another way to get data from Google Dictionary:
http://googlesystem.blogspot.com/2009/12/on-googles-unofficial-dictionary-api.html

Does Google require an SSL url? You're using "http://" but the example script uses "https://"

Related

Python - JIRAerror hhtp 403 url captcha challenge

Hi I am trying to connect to Jira python package JIRA
Here is command
j_url = 'https://myserver.com/jira'
JIRA(j_url, auth=(user, pass), max_retries=5)
I am getting the following error. I was not getting this error before. Only thing is changed, I did changed my password yesterday and it failed few times
JIRAError: JiraError HTTP 403 url: https://xxxxxxx/jira/rest/auth/1/session
text: CAPTCHA_CHALLENGE; login-url=xxxxxx/jira/login.jsp
Any idea what could be possible issue here?
It is solved now.
There is Current failed logins count in Jira profile. If it exceed certain threshold then API is failing. You need to get it reset by Admin

HTTPError: HTTP Error 403: Forbidden. wget with python

I am using Python with Jupyter Notebook.
This program downloads many pdfs and works on other machines, however when putting it on another machine with Windows Server 2016 Standard it shows an error.
The function that is causing the error is:
def download_doc(pasta_pdf,base_links):
os.chdir(pasta_pdf)
for link in base_links['Link_Download_Regulamento']:
if link != None:
wget.download(link)
else:
continue
download_doc(pasta_origem,df_regulamentos_novos)
The error print:
enter image description here
Thanks for your assistance.
You got
HTTPError: HTTP Error 403: Forbidden
If you got information about HTTP response status code, but do not know what it does mean, then you might consult developer.mozilla.org docs, in this case this is 403 Forbidden
The client does not have access rights to the content; that is, it is
unauthorized, so the server is refusing to give the requested
resource. Unlike 401, the client's identity is known to the server.

Trying to access database from my local server

I want to access a database from Zoho Creator using their REST API (https://www.zoho.com/creator/help/api/rest-api/rest-api-add-records.html) I read that I cannot do that from the client side (because CORS isnt implemented or something along those lines) and that I would have to do it from a server.
So I setup a local server using django and I ran a script from the terminal that should add a record to my zoho database, but it doesnt work...
I'm not sure if the script is wrong or if the way I use the server is wrong.
The server is ran by django, I made a simple server with the command "django-admin startproject mysite" and ran the server with "python manage.py runserver".
The name of the app is "synonyms-database", the form is "Main_Form" and the only field there is is called "name". So with that info I followed the API instructions and this is my script:
import requests
payload = {'authtoken': myAPIToken, 'scope': 'creatorapi', 'name': 'test'}
response = requests.request('POST',
'https://creator.zoho.com/api/erik341/json/synonyms-
database/form/Main_Form/record/add/', json=payload)
print(response.headers)
print(response.text)
print(response.url)
And I get this response:
<body>
<div>
An error has occurred. It has been reported to Zoho Creator
support. We will look into this issue .<br> Sorry for the
inconvenience caused.
<p><p>
Go to <a href='%2F'>Home</a>
</div>
</body>
If instead of json=payload I use data=payload the response changes to:
{"code":2945,"message":"INVALID_TICKET"}
The API expects form-encoded data so you should use data=payload instead of json=payload. The json in the URL is the format for the response format, not the request.
You might be able to solve the INVALID_TICKET error by regenerating the token. There's a comment on this post which solved the error by changing the URL from .eu to .com. Make sure that you generate the auth token on a URL that matches your request URL.

Gmail API watch() not working properly

I am trying to run watch() on my inbox and send it to a pub/sub.
However, I keep getting this error:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/gmail/v1/users/me.com/watch?alt=json returned "Invalid topicName does not match projects/western-oarlock/topics/*">
The code I am sending is:
request = {
'labelIds': ['INBOX'],
'topicName': 'projects/flask-app/topics/myTopic'
}
service.users().watch(userId='me', body=request).execute()
Why is it attempting to contact western-oarlock instead of flask-app?
Check if access token you are using is the right one.
Check if .p12 key you are using is from the same project, or try using a new key.
I had the same problem, in my case the cause was access token I used in Google Cloud API OAuth2 authentication which was generated using wrong service account. Hovewer I've read then somewehere on the Internet that wrong .p12 key also can cause this issue.
It ended up having to do with the JSON Secrets file. I was authenticating on the wrong project.

Python mongolab REST api

I am trying to access the mongolab REST api through python. Is the correct way to do this via pythons urllib2? I have tried the following:
import urllib2
p = urllib2.urlopen("https://api.mongolab.com/api/1/databases/mydb/collections/mycollection?apiKey=XXXXXXXXXXXXXXXX")
But this gives me an error:
urllib2.URLError: <urlopen error unknown url type: https>
What is the correct way of doing this? After connecting, how do I go on to POST a document to my collection? If someone could post up a code example, I would be very grateful. Thanks all for the help!
EDIT:
I've recompiled python with ssl support. How do I POST insert a document to a collection using mongolab REST API? Here is the code I have atm:
import urllib
import urllib2
url = "https://api.mongolab.com/api/1/databases/mydb/collections/mycollection?apiKey=XXXXXXXXXXXXXXXX"
data = {"x" : "1"}
request = urllib2.Request(url, data)
p = urllib2.urlopen(request)
Now, when I run this, I get the error
urllib2.HTTPError: HTTP Error 415: Unsupported Media Type
How do I insert documents using HTTP POST? Thanks!
That error is raised if you version of python does not include ssl support. What version are you using? Did you compile it yourself?
That said, when you get a version including ssl, using requests is a lot easier than urllib2, especially when POSTing data.

Categories