unexpected keyword argument 'codec' in XMLConverter - python-3.x

Below error message:
device = XMLConverter(rsrcmgr, retstr, laparams=laparams, codec=codec)
TypeError: __init__() got an unexpected keyword argument 'codec'
Original Code:
rsrcmgr = PDFResourceManager()
retstr = BytesIO()
codec = 'utf-8'
laparams = LAParams()
device = XMLConverter(rsrcmgr, retstr, laparams=laparams, codec=codec)
This is surprisingly working fine in my project setup (python 3.5.3) but not in the new setup (python 3.7.4). Not sure if the this is anyways a problem or if a new version of XMLConverter is now available

As suspected by chris, this issue is due to version mismatch. 2019 version of pdfminer doesn't have keyword codec in the method. So I installed the older version of pdfminer 20181108 which is used in my project as well. Now the code runs without any error

Related

Error about Selenium version using Python's webbot

I'm using Python 3.9 on macOS. I'm trying to start using webbot, but every time I try, I get this error:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
exception: Missing or invalid capabilities
(Driver info: chromedriver=2.39.562713
(dd642283e958a93ebf6891600db055f1f1b4f3b2),platform=Mac OS X 10.14.6 x86_64)
I'm using macOS version 10.4 because I use 32 bit software. The part that really puzzles me is why is says chromedriver=2.39.562713. According to the pip, the driver's version is 103.0.5060.53. If I import selenium and try the command help(selenium), towards the end of the output, I get:
VERSION
4.3.0
Where does this lower version come from? I'm pretty sure that's why I have "missing or invalid capabilities." If I start selenium with:
from selenium import webdriver
driver = webdriver.Chrome()
It starts Chrome as expected. Obviously I'm missing something.
I used to start webbot with:
from webbot import Browser
driver = Browser()
But then, just to be sure, I changed it to:
from webbot import Browser
driver = Browser(True, None, '/usr/local/bin/')
'/usr/local/bin/' being the location of a chrome webdriver installed by brew that is explicitly version 103. No difference.
Solution
The approved response was not the solution, but it led me to the solution.
My version of webbot is the latest, but it has a very different __init__ method:
def __init__(self, showWindow=True, proxy=None , downloadPath:str=None):
Upon further inspection, I saw that the driverPath attribute (that I had tried to use earlier) was completely gone by design. So I decided to print the value of the inner variable driverpath inside the __init__ method. This returned the following:
project_root/virtualenvironment/lib/python3.9/site-packages/webbot/drivers/chrome_mac
There was my guilty party! I renamed that executable and in its place put a symbolic link to the correct binary. That worked.
driver = Browser(True, None, '/usr/local/bin/')
actually sets the downloadPath, not the driverPath. Use the parameter name explicitly
driver = Browser(driverPath='/usr/local/bin/')
From webbot.py
class Browser:
def __init__(self, showWindow=True, proxy=None , downloadPath:str=None, driverPath:str=None, arguments=["--disable-dev-shm-usage","--no-sandbox"]):
if driverPath is not None and isinstance(driverPath,str):
driverPath = os.path.abspath(driverPath)
if(not os.path.isdir(driverPath)):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), driverPath)
if driverPath is None:
driverfilename = ''
if sys.platform == 'linux' or sys.platform == 'linux2':
driverfilename = 'chrome_linux'
elif sys.platform == 'win32':
driverfilename = 'chrome_windows.exe'
elif sys.platform == 'darwin':
driverfilename = 'chrome_mac'
driverPath = os.path.join(os.path.split(__file__)[0], 'drivers{0}{1}'.format(os.path.sep, driverfilename))
self.driver = webdriver.Chrome(executable_path=driverPath, options=options)
If driverPath is None it will set to
/{parent_folder_abs_path}/drivers/chrome_mac or /{parent_folder_abs_path}/drivers/, I'm guessing you have an older chromedriver version there.

decodestrings is not an attribute of base64 error in python 3.9.1

After upgrading from python 3.8.0 to python 3.9.1, the tremc front-end of transmission bitTorrent client is throwing decodestrings is not an attribute of base64 error whenever i click on a torrent entry to check the details.
My system specs:
OS: Arch linux
kernel: 5.6.11-clear-linux
base64.encodestring() and base64.decodestring(), aliases deprecated since Python 3.1, have been removed.
use base64.encodebytes() and base64.decodebytes()
So i went to the site-packages directory and with ripgrep tried searching for the decodestring string.
rg decodestring
paramiko/py3compat.py
39: decodebytes = base64.decodestring
Upon examining the py3compat.py file,i found this block:
PY2 = sys.version_info[0] < 3
if PY2:
string_types = basestring # NOQA
text_type = unicode # NOQA
bytes_types = str
bytes = str
integer_types = (int, long) # NOQA
long = long # NOQA
input = raw_input # NOQA
decodebytes = base64.decodestring
encodebytes = base64.encodestring
So decodebytes have replaced(aliased) decodestring attribute of base64 for python version >= 3
This must be a new addendum because tremc was working fine in uptil version 3.8.*.
Opened tremc script, found the erring line (line 441), just replaced the attribute decodestring with decodebytes.A quick fix till the next update.
PS: Checked the github repository, and there's a pull request for it in waiting.
If you don't want to wait for the next release and also don't want to hack the way i did, you can get it freshly build from the repository, though that would be not much of a difference than my method

configparser() issue in python with IDE Microsoft Code

Specs: Python version 3.7.3 (64-bit)
IDE Microsoft Code (latest edition as of 4/23)
Background I am having issues with executing my code with Configparser only on Microsoft code. I installed other IDE's pycharm etc and I do not have any issues. I prefer Microsoft Code interface / debugging so I would prefer to keep using it. I even went an extra step and installed MS-Code on another server and tried to exec my code with the exact same issue. On a side note if you execute the code in debug mode in ms-code it works without a key error.
This issue is really confusing to me and any help would be appreciated
Current structure of Configparser in code
config = configparser.ConfigParser()
config.read('api_config.ini')
#Reads in each of the api URLs to use from the config file
line_item_reporting = config['apis']['line_item_reporting']
line_item_meta = config['apis']['line_item_meta']
package_reporting = config['apis']['package_reporting']
package_meta = config['apis']['package_meta']
io_meta = config['apis']['io_meta']
io_reporting = config['apis']['io_reporting']
Error code
line_item_reporting = config['apis']['line_item_reporting']
File "C:\ProgramData\Anaconda3\lib\configparser.py", line 958, in getitem
raise KeyError(key)
KeyError: 'apis'
api_config.ini
[general]
meta_pull=50
num_loops=10
index_start=0
index_end=20
password=#######
lookback_window=3
[apis]
io_reporting = https://some_url
line_item_reporting = https://some_url
line_item_meta = https://some_url
package_reporting = https://some_url
package_meta = https://some_url
io_meta = https://some_url

Python firebase_admin.credentials has no attribute Certificate

I'm currently developing for GCP and had used this code already many many times (this is running on RPI3 python 3.7)
def createClient(projid, dev_name):
base = os.getcwd()
base = base.replace("\\",'/')
keydir = '{}/Devices/{}/firebase.json'.format(base, projid.lower())
print(keydir)
cred = credentials.Certificate(keydir)
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://{}.firebaseio.com/'.format(projid.lower())
}, name= dev_name)
But now the code fails with message:
module 'firebase_admin.credentials' has no attribute 'Certificate'>
Please note this code it's working correctly in other RPI why is this not working?!
the error occurs in this line of code:
cred = credentials.Certificate(keydir)
anyone with a clue would be very very appreciated.
Kind Regards!
Edit: I've tried with:
cred = credentials.RefreshToken(keydir)
still the same result now with the error:
module 'firebase_admin.credentials' has no attribute 'RefreshToken'>
note I'm using a service account json file as a key.
Edit2: I missed to add this info in the original post:
firebase-admin==2.17.0
this is all running in a Raspberry Pi 3 B+ (RPI)

TypeError: tf.broadcastTo is not a function

Using tensorflowjs (tfjs-node#1.2.3),
const tf = require('#tensorflow/tfjs-node');
...
imageNetStats = tf.broadcastTo(imageNetStats, [h, w, 3])
gives error TypeError: tf.broadcastTo is not a function
This function was working yesterday and nothing has changed.
broadcastTo has been added to the API only since the version 1.5.x. This explains why the function is not found since you are using the version 1.2.3

Resources