openpyxl version 3.1.0 exhibits different behavior than 3.0.10 - openpyxl

The following code works fine with openpyxl version 3.0.10 and fails with the following error in openpyxl version 3.1.0 :
sheet_index = request.get_array(field_name='file')
Error :
{TypeError}'set' object is not subscriptable
The request is an ExcelRequest.
The code that initiates this request is :
tester = app.test_client()
input_file_path = from_resources('test', 'unit', 'web', 'portfolio_upload_with_version.xlsx')
input_file = FileStorage(stream=open(input_file_path, "rb"), filename="portfolio_upload_with_version.xlsx",
return tester.post("/" + division + "/portfolio/upload", data={"file": input_file},
content_type="multipart/form-data")

Related

Reverse gecoding - geopy.Nominatim module throws urlopen error [SSL: UNKNOWN PROTOCOL]

I am trying to get the address details from Latitude and Longitude using geopy.Nominatim module. Am getting "<'urlopen error [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:727)>" error.
Version Details :
Python version : 2.7
geopy version : 1.23.0
geographiclib : 1.50 (Dependency with geopy)
requests : 2.25.1
chardet : 3.0.4 (Dependency with requests)
urllib3 : 1.25.10 (Dependency with requests)
idna : 2.10 (Dependency with requests)
certifi : 2020.6.20 (Dependency with requests)
Code:
=====
from geopy.geocoders.osm import Nominatim
from geopy.exc import GeocoderServiceError
def reverse(lat,long):
app = Nominatim(user_agent='reverse-geocoding')
coordinates = "{},{}".format(lat,long) # not giving the actual co-ordinates
try:
address_details = app.reverse(coordinates,language="en").raw
return address_details
except GeocoderServiceError as e1:
print (str(e1))
result = reverse(lat,long)
print(result)
================
I have used the following workarounds with the same script.Am getting "<'urlopen error [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:727)>" error
workaround 1: To use the CA bundle used by requests library:
from geopy.geocoders.osm import Nominatim
from geopy.geocoders import options
from geopy.exc import GeocoderServiceError
import ssl
import certifi
def reverse(lat,long):
ctx = ssl.create_default_context(cafile=certifi.where())
options.default_ssl_context = ctx
app = Nominatim(user_agent='reverse-geocoding')
coordinates = "{},{}".format(lat,long) # not giving the actual co-ordinates
try:
address_details = app.reverse(coordinates,language="en").raw
return address_details
except GeocoderServiceError as e1:
print (str(e1))
result = reverse(lat,long)
print(result)
Workaround 2: To disable TLS certificate verification completely:
from geopy.geocoders.osm import Nominatim
from geopy.geocoders import options
from geopy.exc import GeocoderServiceError
import ssl
def reverse(lat,long):
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
options.default_ssl_context = ctx
app = Nominatim(user_agent='reverse-geocoding')
coordinates = "{},{}".format(lat,long) # not giving the actual co-ordinates
try:
address_details = app.reverse(coordinates,language="en").raw
return address_details
except GeocoderServiceError as e1:
print (str(e1))
result = reverse(lat,long)
print(result)
Could anyone please help me to find a fix for this issue.
The error UNKNOWN PROTOCOL is in all probability due to the fact that your request is going via a proxy.
I looked into your code mentioned in Workaround 2. Please mention the proxy explicitly in your code. Try using below code lines:
ctx = ssl.create_default.context()
ctx.check_hostname = True
ctx.verify_mode = ssl.CERT_REQUIRED
options.default_ssl_context = ctx
proxies = {'https':'https://your-proxy-server.com:port'}
app = Nominatim(user_agent="your-agent", proxies=proxies, timeout=10)
This will also help you not to ignore SSL verification completely.

Receiving Error on TFRecordCompressionType.GZIP in Tensorflow 2.0

I get an error below when I run the code below. I have Tensorflow 2.0 installed
test = tf.io.TFRecordOptions(tf.io.TFRecordCompressionType.GZIP)
Error received
AttributeError: module 'tensorflow_core._api.v2.io' has no attribute 'TFRecordCompressionType'
test = tf.io.TFRecordOptions(compression_type = 'GZIP')

Cannot resolve method 'format' in Cucumber reporting

Trying to run a cucumber scenario with reporting to a JSON file, but for some reason the 'format' isn't working. It states 'cannot resolve method 'format'. I'm following a tutorial and can't understand why this isn't working. Any help would be appreciated, thanks
working with selenium/java/intelliJ/testNG
Replace format with plugin as format option was deprecated from V. 1.2.0 onwards on 30-October-2014. Example below -
#RunWith(Cucumber.class)
#CucumberOptions(features = "classpath:features/functional/",
glue = {"com.jacksparrow.automation.steps_definitions.functional" },
plugin = { "pretty","json:target/cucumber-json/cucumber.json",
"junit:target/cucumber-reports/Cucumber.xml", "html:target/cucumber-reports"},
tags = { "#BAMS_Submitted_State_Guest_User" },
strict = false,
dryRun = false,
monochrome = true)

Ensure Ruby version in Nix Dev Environment when using latest version

Currently, the default and latest Ruby in Nix is 2.2.2-p0. When I run nix-env -qaP ruby it returns a list, which says that this ruby version is accessed via nixpkgs.ruby. I expect that this Ruby link will change to stay up-to-date with the latest supported ruby version. There is no optional nixpkgs.ruby_2_2_2 for me to use to ensure my ruby version.
Looking at the .nix definition file at https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/interpreters/ruby/ruby-2.2.2.nix, however, I see that they specify the revision in that script.
So I'm wondering, is there some way for me to specify the revision of the Nix package that I want when I'm listing it in the buildInputs of my Nix expression for creating the development environment (which will be accessed via nix-shell .)? Or is there something else that I might do that would enable me to ensure that ruby 2.2.2-p0 is used for the installation, and not just the latest Ruby, which might change?
Current script:
let
pkgs = import <nixpkgs> {};
in with pkgs; {
rubyEnv = stdenv.mkDerivation rec {
name = "ruby-env";
version = "0.1";
src = ./.;
buildInputs = [
stdenv
ruby
bundler_HEAD
];
};
}
I didn't see this covered in the documentation at http://nixos.org/nix/manual/#chap-writing-nix-expressions
There is no optional nixpkgs.ruby_2_2_2 for me to use to ensure my
ruby version.
Actually there is a ruby_2_2_2 in nixpkgs:
$ nix-env -qaP ruby
nixos.ruby_1_8 ruby-1.8.7-p374
nixos.ruby_1_9 ruby-1.9.3-p551
nixos.ruby_2_0 ruby-2.0.0-p645
nixos.ruby_2_1_0 ruby-2.1.0-p0
nixos.ruby_2_1_1 ruby-2.1.1-p0
nixos.ruby_2_1_2 ruby-2.1.2-p353
nixos.ruby_2_1_3 ruby-2.1.3-p0
nixos.ruby_2_1 ruby-2.1.6-p0
nixos.ruby_2_2_0 ruby-2.2.0-p0
nixos.ruby ruby-2.2.2-p0
nixos.bundler_HEAD ruby-2.2.2-p0-bundler-2015-01-11
By looking at the definition of ruby package in the index, you can see that the current default ruby is just an alias to ruby 2.2:
ruby = ruby_2_2;
that is in turn an alias to ruby 2.2.2:
ruby_2_2 = ruby_2_2_2;
To override the ruby package to a specific ruby version in a nix expression, overridePackages can be used:
let
nixpkgs = import <nixpkgs> {};
pkgs = nixpkgs.overridePackages (self: super: {
ruby = nixpkgs.ruby_2_2_2;
});
in with pkgs;
{
rubyEnv = stdenv.mkDerivation rec {
name = "ruby-env";
version = "0.1";
src = ./.;
buildInputs = [
stdenv
ruby
bundler
];
};
}

Jython multipart post with commons http-client/core

Hello im trying to send a multipart post request and using jython with commons httpclient 4.3.1.
http_client = DefaultHttpClient()
http_post = HttpPost(url)
bin = FileBody(File(file_name), ContentType.APPLICATION_XML)
me = MultipartEntity()
me.addPart('datei', bin)
http_post.setEntity(me)
print "Executing Post Request:", http_post.getRequestLine()
http_response = http_client.execute(http_post)
result_entity = http_response.getEntity()
return EntityUtils.toString(result_entity)
In my opinion the return value should a str with the content, but it is:
"type 'org.apache.http.conn.BasicManagedEntity'"
Where is my mistake?
I do not know the exact answer to your question. And today I have been trying to make a multipart post work from my jython script for a skiuli project I am working on.
Here is how I was able to do it.
First get ez_setup.py from: http://peak.telecommunity.com/dist/ez_setup.py
Then run jython ez_setup.py from the cmd prompt
Second get poster from: http://atlee.ca/software/poster/dist/0.8.1/
Unzip the file
Then run jython setup.py install
Last you can follow this sample code or see more on the atlee site:
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2
register_openers()
upload_url = "http://your.website.com/upload-multipart.php"
#this will upload a file and a json object
#in php the file is in $_FILES and the json is in $_POST
params = {'file': open("test.txt", "rb"), 'jsonData': '[{"foo":"bar", "foo1":"bar1"}]'}
datagen, headers = multipart_encode(params)
request = urllib2.Request(upload_url, datagen, headers)
result = urllib2.urlopen(request)
print result.read()
I hope this helps someone out there. This example will also work for post multipart in python.