Exporting SSRS Reports to PDF from Python - sql-server

I am trying to export/print/generate SSRS reports from Python. It looks like SSPYRS should accomplish exactly what I am looking for. However, I get an error and can't find the ways around it.
import sspyrs
try:
username= "user"
password = "pass"
params_multi = {'param1': value1, 'param2': value2, 'param3': value3}
myrpt = sspyrs.report("http://sqlserver/reportingserrver/reportsfolder/reportname", username, password, params_multi).download('PDF',fileloc)
except Exception as ex:
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
I get the following error:
Report Server does not allow usable data export methods. Update server settings/version to enable XML, Excel, or CSV export.
When I ran the the same reports from the browser everything is working fine. I can also access it without any problems from .net applications. So I doubt it's a permissions issues.
I checked reportserver.config file on SQL Server and PDF rendering is enabled. I am not sure where else I can look.
Any help guidance will be greatly appreciated.

So I had to use NTLM authentication to get it to work for me in my environment. Maybe you could use and/or modify this? I am SQL person, not python, but here goes:
import requests
from requests_ntlm import HttpNtlmAuth
#change username to your username
filename = 'C:\\Users\\username\\Desktop\\report.pdf'
#change username and password to your network login
username = "username"
password = "password"
#url needs to be the special url found by going to the ReportServer, the one with &rs:Command=Render
url = "http://reportservername/ReportServer%2fReportFolder%2fReportName&rs:Command=Render&rs:Format=PDF"
r = requests.get(url, auth=HttpNtlmAuth(username, password))
print(r.status_code)
if r.status_code == 200:
with open(filename, 'wb') as out:
for bits in r.iter_content():
out.write(bits)
This post helped me: https://www.reddit.com/r/Python/comments/67xak4/enterprise_intranet_authentication_and_ssrs/

Related

How to send email to outlook without backend

I have a simple React application and I would like to create a form that sends an email to a specific Outlook adress without having to add my own backend.
I first looked at email.js, a library that works fine for Gmail but not for Outlook in my case. When I try to set up the correct Email, I get:
412Hotmail: Invalid login: 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information. [MW4PR04CA0143.namprd04.prod.outlook.com]
This leads into a maze of powershell commands that, for reasons that are hard to summarize, were very difficult to follow through and actually make it work.
I then tried using https://www.smtpjs.com/, but I can't make it work with React. The following code:
Email.send({
Host : "smtp.yourisp.com",
Username : "username",
Password : "password",
To : 'email#email.com',
From : "you#isp.com",
Subject : "This is the subject",
Body : "And this is the body"
}).then(
message => alert(message)
);
gives the error that "Email is not defined", it doesn't matter where I insert my script tag, in my component or in index.html. I also tried
const script = document.createElement("script");
script.src = "https://smtpjs.com/v3/smtp.js"
inside the component, still does not work.
The only solution that actually works so far is https://formspree.io/, but it is a sub-par solution where the sender is redirected to a Formspree page.
I have a very vague understanding of SMTP, so perhaps I am making some rookie mistake with smtp.js.
Grateful for any help.

Cannot login to Salesforce Sandbox via python API

I am using the python3.7.2 module simple-salesforce==0.74.2 and I am having trouble trying to establish a connection to my salesforce sandbox. I can login to the salesforce production with the same credentials just fine like so:
from simple_salesforce import Salesforce
sf = Salesforce(username='user#domain.com', password='pswd', security_token='mytoken')
Okay cool. Now I attempt to login to my sandbox with the following:
sf = Salesforce(username='user#domain.com.sandbox_name', password='pswd', security_token='mytoken', sandbox=True)
And I get the error:
simple_salesforce.exceptions.SalesforceAuthenticationFailed:
INVALID_LOGIN: Invalid username, password, security token; or user
locked out.
So I tried logging in with a different method:
sf = Salesforce(username='user#domain.com.sandbox_name', password='pswd', security_token='mytoken', domain='sandbox_name')
And this gave a different error:
requests.exceptions.ConnectionError:
HTTPSConnectionPool(host='sandbox_name.salesforce.com', port=443): Max
retries exceeded with url: /services/Soap/u/38.0 (Caused by
NewConnectionError(': Failed to establish a new connection: [Errno 8]
nodename nor servname provided, or not known'))
I am using a Developer sandbox, named sandbox_name, following salesforce's instructions. Can someone give some advice on what I am doing incorrectly?
Solved. Set domain='test' and generate a new token under your sandbox account
this didn't work for me, but what did was:
`sf = Salesforce(
username='my.email#test.com',
password='sadfd8d8d8',
security_token='d8d8asd8f8d8',
instance_url='https://my-dev-org-instance-dev-ed.my.salesforce.com')`
The advice here may be a bit deprecated. After a bit of tinkering, I was able to get the simple_salesforce library working with the Salesforce sandbox on a custom domain with the following code. Note the domain that I am passing to the api as well the sand_box name that needs to be appended to the username.
from simple_salesforce import Salesforce
USER = "user#domain.com.sandbox_name"
PASS = "pass"
SEC_TOKEN = "token"
DOMAIN = "<domain>--<sandbox_name>.<instance>.my"
sf = Salesforce(username=USER, password=PASS, security_token=SEC_TOKEN, domain=DOMAIN)

D3 Connection issue using mvsp java api

I am trying to connect to D3 Database with MVSP java api. So far:
I have downloaded the mvapi.jar
added it in project lib folder
written the sample code for connection inside main method
String url = "jdbc:mv:d3:hostname:portNo";
Properties props = new Properties();
props.setProperty("username", "");
props.setProperty("password", "");
String account = "AGCO";
String password = "";
MVConnection connection = null;
try {
// Getting error at this point
connection = new MVConnection(url,props);
MVStatement mvStatement = connection.createStatement();
connection.logTo(account,password);
MVResultSet results = mvStatement.executeQuery(query);
}
com.tigr.mvapi.exceptions.MVException: server error with errorCode 1023.
I checked the console but I'm not able to figure out the actual cause or whether I am entering the wrong username, password.
Please suggest what I am doing wrong.
First, you have to set a breakpoint or trace which function is throwing the errors. Then check the routes, (FileName) probably you will have much more experience than I do, but keep in mind that giving the full route ("account,filename," where the last comma is important) is never a bad idea while keep you safer and is mandatory if the filename is in a different account that you are logged to.
And like always please verify these things:
You have enough licenses. Try to close any terminal you have opened for testing your queries. Yes you know is true. One connection one license. Sometimes MVSP let you two under the same IP but chek this.
MVSP service is running. See Pick D3 documentation.
Your USER and ACCOUNT are both ENABLED to access in the MVSP server otherwise you won't be able to access these files or login with the user through the API. See the documentation to enable in the MVSP.Menu account.
I hope this helps.

Windows Phone 7 Silverlight Service References CommunicationException: "Server returned an error: Not Found"

I am developing an application for Windows Phone 7. I am trying to use services which are provided by the web site I am trying to get information from. I am using an asynchronous request. So if I try to get information from a web site without any authentication I use this code:
EventSrv.EventSrvSoapClient client = new EventSrv.EventSrvSoapClient();
client.GetAppointmentsAsync();
client.GetAppointmentsCompleted += new EventHandler<EventSrv.GetAppointmentsCompletedEventArgs>(events_completed);
and it works fine. But as soon as I want to use a service from a web site which requires authentication I get a
CommunicationException: _innerException:"Server returned an error: Not Found"
at
public L2P.DocumentsService.GetDocumentsResponse EndGetDocuments(System.IAsyncResult result)
{
object[] _args = new object[0];
//Between this line
L2P.DocumentsService.GetDocumentsResponse _result = ((L2P.DocumentsService.GetDocumentsResponse)(base.EndInvoke("GetDocuments", _args, result)));
//and this line
return _result;
}
I am passing the credentials the following way:
DocumentsService.BaseServiceSoapClient docClient = new DocumentsService.BaseServiceSoapClient();
docClient.ClientCredentials.UserName.UserName = Variables.username;
docClient.ClientCredentials.UserName.Password = Variables.password;
docClient.GetDocumentsCompleted += new EventHandler<DocumentsService.GetDocumentsCompletedEventArgs>(getDocumentsCompleted);
docClient.GetDocumentsAsync();
It actually doesn't matter if I pass the credentials or not, I get the same exception. I don't really know what the problem is, maybe it has nothing to do with the authentication. I've read all the articles here on CommunicationException but they couldn't solve my problem.
Any help will be appreciated!
I've finally figured it out! The server uses Basic Authentication and the header is set to "POST" by default. So I needed to modify the Header, set it to "Basic" and add the credentials as well. Furthermore the
CommunicationException: "Server returned an error: Not Found"
always appear if there is any unhandled exception. So you need to debug and check the _innerException for more information.

Need help debugging a custom authentication plugin for Moodle

I'm trying to authenticate against the user db of my website (CMS based) and it uses a slightly different approach at storing hashed passwords. It uses a randomly generated salt for each user. The salt is stored in the user db along with the hashed passwords. Hence, direct field-mapped authentication (as the External DB plugin does) won't work for me.
To start off, I just mirrored the DB plugin and modified the user_login() procedure to read the hashed password and the salt from the database and then hash the entered password again with the salt and match it up with the password in the database. Here's the code for my user_login() function
function user_login($username, $password) {
global $CFG;
$textlib = textlib_get_instance();
$extusername = $textlib->convert(stripslashes($username), 'utf-8', $this->config->extencoding);
$extpassword = $textlib->convert(stripslashes($password), 'utf-8', $this->config->extencoding);
$authdb = $this->db_init();
// normal case: use external db for passwords
// Get user data
$sql = "SELECT
*
FROM {$this->config->table}
WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."' ";
$authdb->SetFetchMode(ADODB_FETCH_ASSOC);
// No DB Connection
if ( !$rs = $authdb->Execute( $sql ) ) {
$authdb->Close();
print_error('auth_dbcantconnect','auth');
return false;
}
// No records returned
if( $rs->EOF ) {
$rs->Close();
$authdb->Close();
return false;
}
// Get password
$db_password = $rs->fields['user_password'];
$salt = $rs->fields['user_salt'];
// Close DB Conn
$rs->Close();
$authdb->Close();
// Return match
return sha1( $extpassword . $salt ) == $db_password;
}
But when I try to login, username / passwords corresponding to the website (CMS) database are failing. However, the password (for the same user) that was stored in Moodle earlier on (before I tried using this custom plugin) is getting me through.
That means, either my authentication routine is failing or moodle's internal db based auth mechanism is taking precedence over it.
I've enabled ADODB debug mode - but that isn't helping either. When I enable the debug output from Server settings, the error messages are being sent prior to the page headers. Thus the login page won't display at all.
I have all other forms of authentication turned off (except for Manual which can't be turned off) and my own.
Any ideas on how to solve this issue?
Can you confirm the order that the authentication pluggins are displayed? This will determine the order in which they are used. See..
http://docs.moodle.org/en/Manage_authentication
Either way, the behaviour you're seeing suggests that your code is returning false and the fall through logic described here...
http://moodle.org/mod/forum/discuss.php?d=102070
... and here...
http://docs.moodle.org/en/Development:Authentication_plugins
... is kicking in.
Have you tried returning "true" always from your plugin to ensure that it's being called. Then, you can start returning "true" based upon other things (hard coded usernames etc). This approach will allow you to get to the point where you are either continuing to fail or seeing more targetted failures. Are you sure, for example, that it's the user_login function and not the subsequent call to update_user_record that is failing?
Finally, are you sure you're generating the salted password in the exact same way that it was created in the first place? This would be, for me, the most likely cause of the problem. Can you take control of the creation of the salted password so that you own both creation of new users and authentication of users - this would ensure that you were in sync with how the salted password and hash were generated.

Resources