I am trying to submit a form and retrieve some data
with dryscrape but when I execute the program, I get the error:
Traceback (most recent call last):
File "easyjettest.py", line 22, in <module>
originairport_field.set(originairport)
AttributeError: 'NoneType' object has no attribute 'set'
I really can't figure out what is the problem. I've read the documentation and searched as much as I could online.
The code is the following:
import dryscrape
import sys
if 'linux' in sys.platform:
# start xvfb in case no X is running. Make sure xvfb
# is installed, otherwise this won't work!
dryscrape.start_xvfb()
originairport = 'Cyprus (Larnaca) LCA'
destinationairport = 'London Gatwick LGW'
odate = '16/08/2016'
adate = '18/08/2016'
adults = '1'
sess = dryscrape.Session(base_url = 'http://www.easyjet.com/en/')
sess.set_attribute('auto_load_images', False)
sess.visit('/')
originairport_field = sess.at_xpath('.//*[#id="acOriginAirport"]')
originairport_field.set(originairport)
destinationairport_field = sess.at_xpath('.//* [#id="acDestinationAirport"]')
destinationairport_field.set(destinationairport)
odate_field = sess.at_xpath('.//*[#id="oDate"]')
odate_field.set(odate)
rdate_field = session.at_xpath('.//*[#id="rDate"]')
rdate_field.set(rdate)
adults_field = session.at_xpath('.//*[#id="numberOfAdults"]')
adults_field.set(adults)
originairport_field.form().submit()
# extract all links
for link in session.xpath('//a[#href]'):
print link['href']
Check in which line the error is taking place ,probably any of the variables originairport_field, destinationairport_field, odate_field ,rdate_field,adults_field is assigned none.
By the way from where does the session in the lines where you set the values of rdate_field and adults_field come from? isnt that sess
Edit:
From your updated error info probably sess.at_xpath('.//*[#id="acOriginAirport"]') isnt returning anything.
Related
status = confluence.update_page(
parent_id=None,
page_id={con_pageid},
title={con_title},
body='Updated Page. You can use <strong>HTML tags</strong>!')
Using this code gives me the following error:
Traceback (most recent call last):
File "update2.py", line 24, in
status = confluence.update_page(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/atlassian/confluence.py", line 1513, in update_page
if not always_update and body is not None and self.is_page_content_is_already_updated(page_id, body, title):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/atlassian/confluence.py", line 1433, in is_page_content_is_already_updated
current_title = confluence_content.get("title", None)
AttributeError: 'str' object has no attribute 'get'
Does anyone have an idea on how to update a confluence page using python? I've tried various solutions provided even here, but none of them is working for me.
Finally tweaked a code that works. Providing whole code in case anyone would need it later.
import requests
from atlassian import Confluence
confluence = Confluence(
url='https://confluence.<your domain>.com',
token='CyberPunk EdgeRunners')
status = confluence.get_page_by_title(space='ABC', title='testPage')
print(status)
status = confluence.update_page(
parent_id=<a number sequence>,
page_id=<a number sequence>,
title='testpage',
body='<h1 id="WindowsSignatureSet2.4.131.3-2-HandoffinstructionstoOperations">A</h1>'
)
print(status)
I am currently logged on to my BBG anywhere (web login) on my Mac. So first question is would I still be able to extract data using tia (as I am not actually on my terminal)
import pdblp
con = pdblp.BCon(debug=True, port=8194, timeout=5000)
con.start()
I got this error
pdblp.pdblp:WARNING:Message Received:
SessionStartupFailure = {
reason = {
source = "Session"
category = "IO_ERROR"
errorCode = 9
description = "Connection failed"
}
}
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/prasadkamath/anaconda2/envs/Pk36/lib/python3.6/site-packages/pdblp/pdblp.py", line 147, in start
raise ConnectionError('Could not start blpapi.Session')
ConnectionError: Could not start blpapi.Session
I am assuming that I need to be on the terminal to be able to extract data, but wanted to confirm that.
This is a duplicate of this issue here on SO. It is not an issue with pdblp per se, but with blpapi not finding a connection. You mention that you are logged in via the web, which only allows you to use the terminal (or Excel add-in) within the browser, but not outside of it, since this way of accessing Bloomberg lacks a data feed and an API. More details and alternatives can be found here.
I've been asked to translate some words, and I'm using Python to do it. Yandex has an API that is supposed to be used withing Python, documentation here :
https://pypi.org/project/yandex-translater/1.0/
I followed the steps, but Always get the same error that seems to be withing the API, or maybe I'm not setting Something right in my code.
The code goes as follow :
from yandex import Translater
tr = Translater()
tr.set_key('my API key not given here')
tr.set_text("Hello World")
tr.set_from_lang('en')
tr.set_to_lang('fr')
result = tr.translate()
print(result)
I then get this error :
File "C:\Users\BMQT\Desktop\Scraping\test.py", line 2, in <module>
tr = Translater()
File "C:\Program Files\Python37\lib\site-packages\yandex\Translater.py", line 23, in __init__
self.default_ui = locale.getlocale()[0].split('_')[0]
AttributeError: 'NoneType' object has no attribute 'split'
A quick look if you need in the translater.py goes as follow for line 23 :
self.default_ui = locale.getlocale()[0].split('_')[0]
Is the API broken or am I wrong in my code? Thanks for the answers!
I've used another api module called yandex_translate, and it works fine.
from yandex_translate import YandexTranslate
translate = YandexTranslate('mykey')
traduction =('Translate:', translate.translate('bonjour', 'fr-ar'))
print(traduction)
Don't know what was wrong with the previous one, maybe outdated.
translater object need to be created like this: tr = Translater.Translater()
from yandex import Translater
tr = Translater.Translater()
tr.set_key('my API key not given here')
tr.set_text("Hello World")
tr.set_from_lang('en')
tr.set_to_lang('fr')
result = tr.translate()
print(result)
I've been trying to get attachment image data from documents in Cloudant.
I can successfully do it once a document is selected (direct extract with _id, etc).
Now trying to do it in combination with "query" operation using selector, I run into trouble.
Here is my code.
targetName="chibika33"
targetfile="chibitest.png"
#--------------------------------------------------
# get all the documents with the specific nameField
#--------------------------------------------------
myDatabase.create_query_index(fields = ['nameField'])
selector = {'nameField': {'$eq': targetName}}
docs = myDatabase.get_query_result(selector)
#--------------------------------------------------
# get the attachment files to them, save it locally
#--------------------------------------------------
count = 0
for doc in docs:
count=count+1
result_filename="result%03d.png"%(count)
dataContent = doc.get_attachment(targetfile, attachment_type='binary')
dataContentb =base64.b64decode(dataContent)
with open(result_filename,'wb') as output:
output.write(dataContentb)
Causes error as;
Traceback (most recent call last):
File "view8.py", line 44, in <module>
dataContent = doc.get_attachment(targetfile, attachment_type='binary')
AttributeError: 'dict' object has no attribute 'get_attachment'
So far, I've been unable to find any API for converting dict to document object in the python-cloudant-document...[python-cloudant document]: http://python-cloudant.readthedocs.io/en/latest/index.html
Any advise would be highly appreciated.
The returned structure from get_query_result(...) isn't an array of documents.
Try:
resp = myDatabase.get_query_result(selector)
for doc in resp['docs']:
# your code here
See the docs at:
http://python-cloudant.readthedocs.io/en/latest/database.html#cloudant.database.CloudantDatabase.get_query_result
I have a python script that takes a generated CSV and uploads it to Google Docs. It can upload it just fine, put I cannot seem to get it to replace the data, it returns an error I cannot find reference to.
Le Code:
import gdata.auth
import gdata.docs
import gdata.docs.service
import gdata.docs.data
import gdata.docs.client
email = 'admin#domain.com'
CONSUMER_KEY='domain.com'
CONSUMER_SECRET='blah54545blah'
ms_client = gdata.docs.client.DocsClient('Domain_Doc_Upload')
ms_client.auth_token = gdata.gauth.TwoLeggedOAuthHmacToken(CONSUMER_KEY, CONSUMER_SECRET, email)
url = 'http://docs.google.com/feeds/documents/private/full/sd01blahgarbage'
ms = gdata.data.MediaSource(file_path="C:\\people.csv", content_type='text/csv')
csv_entry2 = ms_client.Update(url, ms)
It returns:
Traceback (most recent call last):
File "so_test.py", line 19, in <module>
csv_entry2 = ms_client.Update(ms, url)
File "build\bdist.win-amd64\egg\gdata\client.py", line 717, in update
AttributeError: 'MediaSource' object has no attribute 'to_string'
I cannot find anything about the 'to_string' attribute, so I am lost on the trace. ANy help, much appreciated.
I took a look at the docs and it looks like the Update method takes (entry, ms) where entry needs to be a gdata.docs.data.DocsEntry object. You should be able to get the DocsEntry object by getting a feed from your client.
feed = client.GetDocList()