Pdfkit Html to pdf not working as expected in python - python

I am converting a html file to pdf using pdfkit library in python.
This is what my page looks like in html
And this is what I get after converting it to pdf. It puts "Summary" in the next line, but I want it in the same line.
Here is my python code
import pdfkit
with open("performance_report.html", "rb") as f:
str = f.read()
pdfkit.from_string(str, 'out.pdf')
I have tried Landscape mode as well by using below code in html. But same result.
<head>
<meta name="pdfkit-page-size" content="Legal"/>
<meta name="pdfkit-orientation" content="Landscape"/>
</head>
Html Code
<html>
<head>
<meta name="pdfkit-page-size" content="Legal"/>
<meta name="pdfkit-orientation" content="Landscape"/>
</head>
<h1> Performance report for date: 2018-05-27 </h1> <br><br> <div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style=" position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
flex: 0 0 75%;
max-width: 60%;
">
<div style="background-color: #fff; position: relative;
margin-bottom: 1.5rem;
border: 0;
border-radius: 0.2rem;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.15);
margin-left: auto !important;
margin-right: auto !important;
padding-top: 0 !important;">
<div style=" padding: 0.75rem 1.25rem;
border-bottom: 1px solid transparent;
font-weight: 500;background: #F0F8FF;">Requests (%)</div>
<div style="padding: 1.25rem;padding-left: 0.5rem !important;padding-right: 0 !important;">
<img src="cid:request_offload">
</div>
</div>
</div>
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;flex: 0 0 25%;
max-width: 20%;">
<div style="background-color: #fff; position: relative;
margin-bottom: 1.5rem;
border: 0;
border-radius: 0.2rem;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.15);
margin-left: auto !important;
margin-right: auto !important;
padding-top: 0 !important;">
<div style=" padding: 0.75rem 1.25rem;
border-bottom: 1px solid transparent;
font-weight: 500;background: #F0F8FF;">Summary</div>
<div style="padding: 1.25rem;padding-left: 1rem !important;
padding-right: 1rem !important;height: 245px; box-sizing: border-box;">
<div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style=" position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;">
<div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; font-size: 14px;
font-weight: bold; flex: 0 0 50%;
max-width: 50%;">Total:</div>
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; flex: 0 0 50%;
max-width: 50%;">1.03B </div>
</div>
<div style=" display: flex; flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px; margin-bottom: 1rem !important;margin-top: 1rem !important;"></div>
<div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; font-size: 14px;
font-weight: bold; flex: 0 0 50%;
max-width: 50%;">Peak:</div>
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;flex: 0 0 50%;
max-width: 50%;">2.48 %</div>
</div>
<div style="display: flex; margin-top: 0 !important;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;flex: 0 0 100%;
max-width: 100%;">
<small style="color: #808080;font-weight: normal !important;
font-size: 85% !important;">at Sun, 27 May 2018 00:50:00 -0000</small>
</div>
</div>
<div style=" display: flex; flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px; margin-bottom: 1rem !important;margin-top: 1rem !important;"></div>
<div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; font-size: 14px;
font-weight: bold; flex: 0 0 50%;
max-width: 50%;">Least:</div>
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; flex: 0 0 50%;
max-width: 50%;">0.45 %</div>
</div>
<div style="display: flex; margin-top: 0 !important;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;flex: 0 0 100%;
max-width: 100%;">
<small style="color: #808080;font-weight: normal !important;
font-size: 85% !important;">at Sun, 27 May 2018 13:15:00 -0000</small>
</div>
</div>
<div style=" display: flex; flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px; margin-bottom: 1rem !important;margin-top: 1rem !important;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</html>

I finally manage to get the summary next to the requests. You have to use a table in your html. Here is an example below. It is working, the width of the two columns are not perfect, so you can just play around with the width paramaters (I removed it from the html for now):
<html>
<h1> Performance report for date: 2018-05-27 </h1> <br><br> <div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<table style="width:100%">
<tr>
<th>
<div style=" position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
flex: 0 0 75%;
max-width: 60%;
">
<div style="background-color: #fff; position: relative;
margin-bottom: 1.5rem;
border: 0;
border-radius: 0.2rem;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.15);
margin-left: auto !important;
margin-right: auto !important;
padding-top: 0 !important;">
<div style=" padding: 0.75rem 1.25rem;
border-bottom: 1px solid transparent;
font-weight: 500;background: #F0F8FF;">Requests (%)</div>
<div style="padding: 1.25rem;padding-left: 0.5rem !important;padding-right: 0 !important;">
<img src="cid:request_offload">
</div>
</div>
</th>
<th>
</div>
<div style="position: relative;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;flex: 0 0 25%;
max-width: 20%;">
<div style="background-color: #fff; position: relative;
margin-bottom: 1.5rem;
border: 0;
border-radius: 0.2rem;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.15);
margin-left: auto !important;
margin-right: auto !important;
padding-top: 0 !important;">
<div style=" padding: 0.75rem 1.25rem;
border-bottom: 1px solid transparent;
font-weight: 500;background: #F0F8FF;">Summary</div>
<div style="padding: 1.25rem;padding-left: 1rem !important;
padding-right: 1rem !important;height: 245px; box-sizing: border-box;">
<div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style=" position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;">
<div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; font-size: 14px;
font-weight: bold; flex: 0 0 50%;
max-width: 50%;">Total:</div>
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; flex: 0 0 50%;
max-width: 50%;">1.03B </div>
</div>
<div style=" display: flex; flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px; margin-bottom: 1rem !important;margin-top: 1rem !important;"></div>
<div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; font-size: 14px;
font-weight: bold; flex: 0 0 50%;
max-width: 50%;">Peak:</div>
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;flex: 0 0 50%;
max-width: 50%;">2.48 %</div>
</div>
<div style="display: flex; margin-top: 0 !important;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;flex: 0 0 100%;
max-width: 100%;">
<small style="color: #808080;font-weight: normal !important;
font-size: 85% !important;">at Sun, 27 May 2018 00:50:00 -0000</small>
</div>
</div>
<div style=" display: flex; flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px; margin-bottom: 1rem !important;margin-top: 1rem !important;"></div>
<div style="display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; font-size: 14px;
font-weight: bold; flex: 0 0 50%;
max-width: 50%;">Least:</div>
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px; flex: 0 0 50%;
max-width: 50%;">0.45 %</div>
</div>
<div style="display: flex; margin-top: 0 !important;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;">
<div style="position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;flex: 0 0 100%;
max-width: 100%;">
<small style="color: #808080;font-weight: normal !important;
font-size: 85% !important;">at Sun, 27 May 2018 13:15:00 -0000</small>
</div>
</div>
<div style=" display: flex; flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px; margin-bottom: 1rem !important;margin-top: 1rem !important;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</th>
</tr>
</table>
</html>

Related

How do I add image to html email background?

I am trying to create an automated email script for birthdays. However i can send the text email with an image as an attachment but I want the image to be in the background of the text. Like how it is when you open some websites this is a birthday email style that I'm trying to clone. I've got all the other things setup but when i test it, the background image does not appear. Just text box box
this is the code I wrote: I'm not that good a programmer to be sincere. And the ~ in there so that a function will read the html file and replace the ~ with my message[the wish].
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="with=device-with, initial-scale=1.0">
<style>
*
{
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
.header
{
background-image: url('birthday.png');
background-repeat: repeat-y no-repeat;
background-color: #333;
min-height: 100vh;
width: 100%;
background-image: linear-gradient(rgba(4,9,30,0.7),rgba(4,9,30,0.7)), url =("/images/birthday.png");
background-position: center;
background-size: cover;
position: relative;
}
.text-box
{
color:;
background: transparent;
position: absolute;
background-color: aliceblue;
width: auto;
height: auto;
margin: 5% 5%;
border-radius: 10px;
padding: 0px;
}
.tin-line
{
position: relative;
top: 10%;
background-color: cornflowerblue;
width: 100%;
height: 10px;
border-radius: 1px;
}
.message-box
{
position: relative;
top: 13%;
padding: 10px;
}
p
{
font-family: cursive;
font-size: 15px;
font-weight: 600;
text-align: center;
color: black;
}
.last
{
position: relative;
bottom: 5%;
padding: 10px;
font-family: cursive;
font-size: 20px;
font-weight: 700;
}
.head
{
position: relative;
top: 5%;
height: 50px;
width: 100%;
margin: auto;
text-align: center;
font-family: cursive;
}
</style>
</head>
<body>
<section class="header">
<div class="text-box">
<div class="head"><h1>✨HAPPY BIRTHDAY!✨</h1></div>
<div class="tin-line">
</div>
<div class="message-box"><br>
<p>~</p>
</div>
<div class="last">
<p>Best wishes,<br> Dillon</p>
</div>
</div>
</section>
</body>
</html>
This is the output:
Results of email output
There's some advice at backgrounds.cm which may help. Wrap your message in a table and apply the background to a cell. Note that there's two places the image url is defined:
<div style="background-color:#7bceeb;">
<!--[if gte mso 9]>
<v:background xmlns:v="urn:schemas-microsoft-com:vml" fill="t">
<v:fill type="tile" src="https://i.imgur.com/YJOX1PC.png" color="#7bceeb"/>
</v:background>
<![endif]-->
<table height="100%" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="top" align="left" background="https://i.imgur.com/YJOX1PC.png">
Your message here
</td>
</tr>
</table>
</div>
If you're wanting to attach the image then you'll need to use Content-Disposition: inline & Content-ID: headers for the attachment and refer to the image using a cid: link.

text under symbols in the sidebar menu

Very new to CSS and HTML, but right now working on Django one-page project.
Under icons, I would like to place some text, but there is an issue with the borders.
Right now text wrapping works not very well, I would like to center text under the icon and have at least 3 or 4 straight strings.
Maybe there are issues that this text and icons should be in the container, IDK, will be very happy to hear any solution and suggestions for my portfolio project.
Thank you!
Here is my HTML:
body {
background: url(https://images.unsplash.com/photo-1534258936925-c58bed479fcb?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=889&q=80) no-repeat center center fixed;
background-size: cover;
}
#background {
position: fixed;
top: 260px;
left: 0px;
width: 100%;
height: 50%;
background-color: white;
z-index: -1;
opacity: 0.8;
}
.social-menu ul {
position: absolute;
top: 25%;
left: 50%;
transform: translate(-50%, -50%);
padding: 0;
margin: 0;
display: flex;
}
.social-menu ul li {
list-style: none;
margin: 0 20px;
}
.social-menu ul li .fab {
color: #000000;
font-size: 60px;
line-height: 75px;
transition: .5s;
}
.social-menu ul li .fab:hover {
color: #ffffff;
}
.social-menu ul li a {
position: relative;
display: block;
width: 80px;
height: 80px;
border-radius: 50%;
background-color: white;
opacity: 0.8;
text-align: center;
transition: 0.5s;
transform: translate(0, 0px);
box-shadow: 0px 7px 5px rgba(0, 0, 0, 0.5);
}
.social-menu ul li a:hover {
transform: rotate(0deg) skew(0deg) translate(0, -10px);
}
.social-menu ul li:nth-child(1) a:hover {
background-color: #FF3371;
}
.social-menu ul li:nth-child(2) a:hover {
background-color: black;
}
.social-menu ul li:nth-child(3) a:hover {
background-color: blue;
}
.title {
color: black;
font-size: 25px;
padding-top: 220px;
margin-left: 445px;
}
.icons {
position: absolute;
top: 60%;
left: 50%;
transform: translate(-50%, -50%);
padding: 0;
margin: 0;
display: flex;
color: red;
}
.icons li {
list-style: none;
margin: 0 140px;
font-size: 50px;
}
.icons-text {
position: absolute;
top: 76%;
left: 52%;
transform: translate(-50%, -50%);
padding: 0;
margin: 0;
display: flex;
}
.icons-text li {
list-style: none;
margin: 0 100px;
font-size: 10px;
}
<!DOCTYPE html> {% load static %}
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="{% static 'style.css' %}">
<script src="https://kit.fontawesome.com/5476287230.js" crossorigin="anonymous"></script>
</head>
<body>
<div class="social-menu">
<ul>
<li><i class="fab fa-instagram"></i></li>
<li><i class="fab fa-tiktok"></i></li>
<li><i class="fab fa-facebook"></i></li>
</ul>
</div>
<div class="title">
<h1>ЧТО ВЫ ПОЛУЧАЕТЕ?</h1>
</div>
<div id="background"></div>
<div class="icons">
<li><i class="fas fa-utensils"></i></li>
<li><i class="fas fa-dumbbell"></i></li>
<li><i class="fas fa-clock"></i></li>
<li><i class="fas fa-heartbeat"></i></li>
</div>
<div class="icons-text">
<li>
<h1>План питания с учетом Ваших вкусовых потребностей</h1>
</li>
<li>
<h1>Тренировки для любого уровня подготовки</h1>
</li>
<li>
<h1>Максимально быстрые результаты</h1>
</li>
<li>
<h1>Тело, о котором Вы могли только мечтать</h1>
</li>
</div>
</body>
</html>

I am trying to work out absolute Xpath an Add button that is a child element

I am having trouble identifying the Add button on our website which I am in the process of automating. Python, Webdriver.
I have tried few Xpath suggestions it does not work. I have spoken to the dev and she says the button is outside of the iFrame and there are other Add buttons on the page. I need to find the unique one. I should use an Absolute Xpath and start from the parent and work my way down to the child.
Does anyone know what Xpath I can use to do this please using the Ancestor or sibling keyword of Xpath? Thanks.
The button I am trying to locate is here:
<div class="gwt-HTML" style="margin-left: 15px;">Add...</div>
The HTML is as follows (I have shortened it to make it easier to read for you)
root
<div class="gwt-TabLayoutPanelTabs" style="position: absolute; left: 0px; right: 0px; bottom: 0px; width: 16384px;"> <!-- this is the parent -->
| <...>
| | <div class="gwt-HTML">Operations</div>
| | <div class="gwt-HTML">Administration</div> <!-- The Add button is in the same position as this div -->
| </div>
| <div>
| | <div class="gwt-TabLayoutPanelContentContainer" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
| | | <div></div>
| | | <div></div>
| | | <div></div>
| | | <div></div>
| | | <div></div>
| | | <div></div>
| | | <div>
| | | | <!--I need this one. This div is at index 7 which has the Add button-->
| | | | <button class="gwt-Button" type="button">
| | | | <div style="position: absolute; margin-left: 2px;">
| | | | <div class="gwt-HTML" style="margin-left: 15px;">Add...</div>
| | | | </button>
| | | | <button class="gwt-Button" type="button" disabled="">
| | | | <...>
| | | </div>
| | </div>
| </div>
</div>
The full HTML is as follows:
<html style="overflow: hidden;">
<head>
<body style="margin: 0px;">
<iframe id="__gwt_historyFrame" style="position: absolute; width: 0; height: 0; border: 0;" tabindex="-1" src="javascript:''"/>
<noscript> <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif;"> Your web browser must have JavaScript enabled in order for this application to display correctly.</div> </noscript>
<script src="spinner.js" type="text/javascript"/>
<script type="text/javascript"> cImageSrc = 'images/sprites.gif'; new imageLoader(cImageSrc, 'startAnimation()'); var info = { "cc4Address" : "https://riaz-pc.company.local:8889/ClearCore", "rrdAddress" : "https://riaz-pc.company.local:8889/ClearCoreRRD", "gazAddress" : "https://riaz-pc.company.local:8889/Gazetteer", "debugEngine" : "null", "secure" : "true", "suppressErrors" : "true", "testing" : "null", "serverName" : "riaz-pc.company.local" }; var timeout = { "timeoutAlerts" : "300000", "timeoutDefault" : "5000", "timeoutLogout" : "3600000", "timeoutProgress" : "5000", "timeoutSoap" : "300000", "timeoutClearDb" : "3600000" }; var cache = { "cacheMax" : "500", "pageSize" : "25", "startTrig" : "50", "endTrig" : "450", "maxUsnSize" : "1000", "defaultPageSize" : "500" }; var ignoreVersion = { "major" : "true", "minor" : "true", "incremental" : "true" }; var guiVersion = { "major" : "5", "minor" : "1", "incremental" : "1", "build" : "5565" }; </script>
<script src="ClearCore/ClearCore.nocache.js" type="text/javascript"/>
<script defer="defer">ClearCore.onInjectionDone('ClearCore')</script>
<iframe id="ClearCore" src="javascript:''" style="position: absolute; width: 0px; height: 0px; border: medium none;" tabindex="-1"/>
<div style="position: absolute; z-index: -32767; top: -20cm; width: 10cm; height: 10cm; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; overflow: hidden; left: 1px; top: 1px; right: 1px; bottom: 1px;">
<div class="gwt-TabLayoutPanel" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 30px;">
<div class="gwt-TabLayoutPanelTabs" style="position: absolute; left: 0px; right: 0px; bottom: 0px; width: 16384px;">
<div class="gwt-TabLayoutPanelTab GAT4PNUK gwt-TabLayoutPanelTab-selected" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTabInner">
<div class="gwt-HTML">Operations</div>
</div>
</div>
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTabInner">
<div class="gwt-HTML">Administration</div>
</div>
</div>
</div>
</div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 30px; right: 0px; bottom: 0px;">
<div class="gwt-TabLayoutPanelContentContainer" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; overflow: hidden; left: 0%; top: 0%; width: 100%; height: 100%;">
<div class="gwt-TabLayoutPanelContent" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;" aria-hidden="false">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 35px;">
<div class="GAT4PNUDP GAT4PNUKN" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div class="GAT4PNUGP">
<div class="GAT4PNUCP">
<div>
<select class="gwt-ListBox GAT4PNUEP" style="left: 445px;">
<option value="More tools...">More tools...</option>
<option value="Statistics">Statistics</option>
<option value="Snapshot Trending">Snapshot Trending</option>
<option value="Task Statistics">Task Statistics</option>
<option value="User Alerts">User Alerts</option>
</select>
</div>
</div>
</div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 35px; right: 0px; bottom: 0px;">
<div class="gwt-SplitLayoutPanel" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; bottom: 0px; width: 160px;">
<div style="overflow: auto; position: absolute; background-color: rgb(254, 255, 238); left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: relative;">
<div>
<select class="gwt-ListBox" style="width: 100%;">
<div class="GAT4PNUDG" __gwtcellbasedwidgetimpldispatchingfocus="true" __gwtcellbasedwidgetimpldispatchingblur="true" role="tree">
<div style="overflow: hidden;">
<div>
<div>
<div aria-selected="false" role="treeitem" aria-setsize="1" aria-posinset="1" aria-expanded="true" aria-level="1">
<div class="GAT4PNUIF GAT4PNUAG" style="padding-left: 0px;">
<div style="overflow: hidden;">
<div>
<div>
<div aria-selected="false" role="treeitem" aria-setsize="3" aria-posinset="1" aria-expanded="false" aria-level="2">
<div aria-selected="false" role="treeitem" aria-setsize="3" aria-posinset="2" aria-expanded="false" aria-level="2">
<div aria-selected="false" role="treeitem" aria-setsize="3" aria-posinset="3" aria-expanded="false" aria-level="2">
<div class="GAT4PNUIF" style="padding-left: 16px;">
<div class="GAT4PNUIF GAT4PNUKF" style="padding-left: 16px;position:relative;" onclick="">
<div class="GAT4PNUJF" style="left: 0px;width: 15px;height: 15px;position:absolute;">
<div class="GAT4PNULF">
<div style="padding-left: 22px;position:relative;zoom:1;">
<div style="left:0px;margin-top:-8px;position:absolute;top:50%;line-height:0px;">
<div>
<span class="" title="Tasks" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;">Tasks</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="GAT4PNUHF" style="display: none;">Empty</div>
<a class="GAT4PNUPF" href="javascript:;" style="display: none;">Show more</a>
</div>
</div>
</div>
</div>
<div class="GAT4PNUHF" style="display: none;" tabindex="0">Empty</div>
<a class="GAT4PNUPF" href="javascript:;" style="display: none;">Show more</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div style="position: absolute; overflow: hidden; left: 160px; top: 0px; bottom: 0px; width: 8px;">
<div class="gwt-SplitLayoutPanel-HDragger" style="width: 8px; position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;"/>
</div>
<div style="position: absolute; overflow: hidden; left: 168px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 24px;">
<div class="workspacetoolbar" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div>
<div style="position: absolute; top: 3px; left: 5px;">
<span class="gwt-InlineLabel" style="font-weight: bold; color: black; margin-right: 5px; margin-left: 20px;">Reports</span>
<div class="GAT4PNUMP">
<button class="gwt-Button" type="button">
<div style="position: absolute; margin-left: 2px;">
<img border="0" style="width:14px;height:14px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAACyklEQVR42l2SeUjTUQDHn62mbmr+kXk08WCpbJmY4p1ppY5Mu4hAE8XQmRVpTbyyPxIzyeaB06ZtHh2baxvqbAZjlorzSE2lQ5MOg1Iw/CPRMPD37adkRd/Hhy883of3eO8RqVS6rarqbnWjXKGSVDf11koejUlqlO9rqjULVZXalYL8BlNiQlHx0ZhLAYQQJtmMTqdjGQwmzM8Dc3PA7OwqpqaWMTGxBJNpEZ2dH1FfP4i8PCUEAmEmrVhviFKpjqXX92I9MzPfqdGhz5TRMAy12oim5g5IalRUpViJa/ky+O6NVNKKN40ZUYlNlo3aUeinVrH49SdkpiZ0Dz6njDojOh60oaVOg/JyDa7kNsPLK6yLlgI3RPZFm8vidgUejy3BOA5EtSbAvykYdfpRRBePw71wBC43RhCUo4crL2JdDKLZQhhJjDhOmQMCFP7gy/3g+dAd5z9Eg1O/B1rDIKrvqJFbrEZqdgs8PEP/ir6nfe3iZScR3OOGtNlDyF84gXtrQpQuJ8Khlo8L6iWQvGnwsg1w9gzX/xFVqmdWiq4e+MtiwG10Ak/JQdG3U9glc0ab4SlKb93E1gZC2UutsT3Q9pM5YQs2RJGohS2p0KFvbAV13dPUPnkEHOu4KG7rg0tJJ0hRA44PcHHGEALiR94QH3KW7m0kJaXRoiiv5a1GOQlN+xcktxZQZQotrl7vgqWUIL7fHRmvIqi0yVDqoJELVi4TxIl4rj+lWWR4yhFRtvydVDIAuaQfhaL7yBLKYFdji4Te/Uh9GUIJX4RRcWo+rM4x1wibHN78QJYBfscS0tMrZpKTbv+Ijc2ajjyQPLQj3HU4LCNqOeiJE2JVPBAv8ppGTMzJbvJPbDgcvsDOzq2EzbYVM5kWheaElWnv4yC3yGHAKpVJEQ9aIsRx43L+C4vGmYb7u3fSx7KnhzfdUfROHvQcY33hL6HaY35wVehRAAAAAElFTkSuQmCC) no-repeat 0px 0px;" src="http://justin-pc.infoshare.local:8080/clearcore501/ClearCore/clear.cache.gif" onload="this.__gwtLastUnhandledEvent="load";"/>
</div>
<div class="gwt-HTML" style="margin-left: 15px;">Add...</div>
</button>
<button class="gwt-Button" type="button" disabled="">
<button class="gwt-Button" type="button" disabled="">
<div class="GAT4PNUMP">
<button class="gwt-Button" type="button" title="Run the selected reports" disabled="">
<button class="gwt-Button" type="button" title="View the selected report" disabled="">
<button class="gwt-Button workspacebuttontext130" type="button" title="Conditional report" disabled="">Conditional report ▼</button>
<div class="GAT4PNUMP">
<select class="gwt-ListBox" style="height: 20px; margin-right: 5px;" disabled="">
</div>
<img class="gwt-Image helplink pointer" border="0" style="width:16px;height:16px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADAElEQVR42m1TW0iTYRieE7tUB17ajRBFeBOUYaBoTtG8ULQMxKR0HgjBoVJh4CEtPPw6IUHKQ2o1nCPNAwax2WZzrjyl8zCn/puHf3PN4zZSEnv6tv6WlQ88Nx/f877f877Px+Ecw+LiordSqSxQq9XKifFxRjMywnR3dw3V19cXRkVFnSZXThF6cE4CwzD8ublZ88E3Bxy2XRhMVhgYK2w7W7CYGUgkEnNOTk4yuepDyP1PbKBporWj5YMRD97ZIexzIEO6i+R2C2r6l7Bl3YC0s/MgLi4ui0j83EXGxsZ8ZrRas8NuAyXbhEj9A5TqEKWyfeT37iFDso34ZgvutBpgMa2jhqJMPB4vln2JB0culxc4bHt4oVhBjeoIAwvfsbZziN+wHxyha3IX4U9XUdGjh3ZqAqGhoQ1EHEjoxVEoFMrtTSvuD9jxRG6D0boP3foOUit7kVDyxl0osm4BISIjVmk9UlJSNEScQMjjDKtUjH7F5PJc2GPF3QY10urkyG6ZxtzaHkYXzMhtUCCsSovAChpTszoIhbkMEecR+nNkMhmjN5ggkO4hr2cbQimDnNdGd+fwex0IKx1ESLUO58ppTEzNIjs701ngEWEARywWDzmHk/zqKwQdm8js3MLtthVcK+l3iSMrRhEhWsLlqmUEUUbQizpER0d/chegKKqQXtajum8B8S0W3GzdQOKzPy+IqNXjSg2Ns2VLKJHOQERVIiAgQOy2EBMT49/U2GheNS4j7eUKrtavg187j6D8t7gg7MbFsmmX+MZzA1RKGZKSkkyenp7N7iE6V5Genp7c3NR0oNfNorxrHqEiA84XfcGZh5O4VE2jWKLF0OB7ZAgE+yQDbURT5F4jm20f4iurpKjIJG5vxdS4BiOfJzCsGYX64yAelxa7Ovv6+jrFVYSR7iCxcMbSz9vbOzY4OLjhemKiRiAQrKWm3lrj8/kap2cul9vEdo78K8rHwGWrBrL+nEMqZZnHngWe+JmOwYP1xXNN2LmmX/Rnz7z+/c4/ARDk76ne92ZwAAAAAElFTkSuQmCC) no-repeat 0px 0px;" src="http://justin-pc.infoshare.local:8080/clearcore501/ClearCore/clear.cache.gif" onload="this.__gwtLastUnhandledEvent="load";"/>
</div>
</div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 24px; right: 0px; height: 24px;">
<div style="position: absolute; overflow: hidden; left: 0px; top: 48px; right: 0px; bottom: 0px;">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
</div>
</div>
</div>
</div>
<div style="position: absolute; overflow: hidden; top: 1px; right: 1px; width: 30px; height: 25px;">
<div style="position: absolute; overflow: hidden; left: 0px; top: -25px; right: 0px; height: 25px;">
</div>
</div>
</div>
<div style="display: none;" aria-hidden="true"/>
</body>
</html>
I have managed to find the Add button and click it now using the following Xpath.
driver.find_element_by_xpath("/html/body/div[2]/div[2]/div/div[2]/div/div[3]/div/div[8]/div/div[3]/div/div[4]/div/div[2]/div/div[2]/div/div/button[1]")
I understand it is not the best way because if the structure changes the Xpath will break. I will use this for now until i find a better way.
I have updated the HTML in my question if someone could provide a better Xpath.
The parent class is class='gwt-TabLayoutPanelTabs'
The next parent class is Administration
This is where the button is, it is in the Administration class
If i use the following Xpath I can get to the Administration class but then I do not know how to get to the button.
//div[#class='gwt-TabLayoutPanelTabs']/div[7]
Thanks.
Try the following?
//button[#class='gwt-Button']/div[text()='Add...']
or just
//div[text()='Add...']
Thanks!

redirection in html failed

I have a html:
{% load staticfiles %}
<div style="margin:0 auto; width:900px">
<ul id="nav">
<li id="notification_li">
<a href="#" id="notificationLink">
<div id="notify"> <img src="{% static "images/notification.png" %}" width="20" height="20" />
{% if unseen_notifications.count > 0 %}
<span id="notification_count">
{{unseen_notifications.count}}</span>
{% endif %}
</div></a>
<div id="notificationContainer">
<div id="notificationTitle">Inbox</div>
<div id="notificationsBody">
Home
</div>
<div id="notificationFooter">See All</div>
</div>
</li>
</ul>
</div>
Here I have "Home" inside id "notificationContainer". When I click Home it doesnt redirect but outside "notificationContainer" it redirects. Inside notification container I am willing to put notifications. But it doesnt redirect.
My style for this:
#notification_li{position:relative}
#notificationContainer {
background-color: #FFF;
border: 1px solid rgba(100, 100, 100, .4);
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
position: absolute;
top: 30px;
margin-left: -170px;
width: 400px;
z-index: 11;
display: none;
}
#notificationContainer:before {
content: '';
display: block;
position: absolute;
width: 0;
height: 0;
border: 10px;
margin-top: -20px;
margin-left: 188px;
}
#notificationTitle {
z-index: 1000;
font-weight: bold;
padding: 8px;
font-size: 15px;
background-color: #ffffff;
width: 384px;
border-bottom: 1px solid #dddddd;
}
#notificationsBody {
padding: 0px 0px 0px 0px !important;
margin: 0px;
min-height:300px;
font-size:14px;
display: block;
}
#notificationsBody a{ color: #000;}
#notification_count {
padding: 3px 7px 3px 7px;
background: #cc0000;
color: #ffffff;
font-weight: bold;
margin-left: 0px;
border-radius: 20px;
position: absolute;
margin-top: -7px;
font-size: 11px;
}
#notificationFooter {
background-color: #e9eaed;
text-align: center;
font-weight: bold;
padding: 8px;
font-size: 12px;
border-top: 1px solid #dddddd;
}
You need to define a URL in your urls.py
and if you want to use it like this <a href="{% url "ask_question" %}"> then add a name to your url and use it like this <a href="{% url "home" %}">
if your home has a view then:
url(r'^people/', "myapp.views.people", name="people"),
if it is only a template you can use something like this:
url(r'^home/',TemplateView.as_view(template_name="homepage.html"), name="home"),
I think you misunderstood Ebtessam's answer. Not only do you need to configure the URL, you also need to reference that URL correctly in the HTML.
You have:
Home
Change to:
Home
The above assumes that within your URL you defined something that looks similar to:
url(r'^home/',views.your_home_view_here, name="home"),
Notice the name="home".In your template you reference the view with that name, hence:
{% url 'home' %}

How to call web service which is developed in Python's ladon framework from iOS app?

The web services are built on Python's Ladon framework.
Web Service URL is: http://ladonize.org/python-demos/Calculator
The code for calling web service is as below :
NSString *requestString = [NSString stringWithFormat:
#"http://ladonize.org/python-demos/Calculator"];
NSString *jsonString = [NSString stringWithFormat:#"{\"methodname\":\"add\",\"args\": {\"a\":\"123\",\"b\":\"123\"}}"];
NSData *jsonData = [NSData dataWithBytes: [jsonString UTF8String] length: [jsonString length]];
NSURL *url = [NSURL URLWithString:requestString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"POST"];
[request setHTTPBody: jsonData];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
[request setValue:[NSString stringWithFormat:#"%d", [jsonData length]] forHTTPHeaderField:#"Content-Length"];
NSError *errorReturned = nil;
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&errorReturned];
if (errorReturned) {
NSLog(#"Error %#",errorReturned.description);
}
else
{
NSError *jsonParsingError = nil;
NSMutableArray *arrDoctorInfo = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments error:&jsonParsingError];
NSString* newStr = [NSString stringWithUTF8String:[data bytes]];
NSLog(#"Dict %#",newStr);
}
And I am getting following Response
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>Calculator</title>
<style>
body { margin: 0px; padding: 0px; font-family: verdana; font-size: 12pt; background-color: #FCFCFC; }
div.service-header {
height: 34px;
font-weight: bold; padding: 10px; font-size: 30px; color: white; border-bottom: 1px solid black; background: #70803C;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#A0B06C', endColorstr='#70803C'); background: -webkit-gradient(linear, left top, left bottom, from(#A0B06C), to(#70803C)); background: -moz-linear-gradient(top, #A0B06C, #70803C);
text-shadow: #555555 2px 3px 3px;
}
div.service-header div.service-title {position: relative; float:left}
div.service-header .skin-selector {padding-top: 8px; margin-bottom: 0; position:relative; float: right; font-size: 12pt;}
div.service-overview {
float: right; margin: 20px; width: 200px;
-moz-border-radius: 7px 7px 7px 7px; -webkit-border-radius: 7px 7px 7px 7px; border-radius: 7px 7px 7px 7px; background-color: #F6F6F6; border: 1px solid #E6E6E6; border-collapse: separate; font-size: 11px; padding: 10px; margin-right: 20px;
-moz-box-shadow: 2px 2px 4px #555; -webkit-box-shadow: 2px 2px 4px #555; box-shadow: 2px 2px 4px #555;
}
div.service-overview div.headline { font-weight: bold; font-size: 18px; }
div.service-overview div.title { font-weight: bold; margin: 4px; font-size: 1.2em; }
div.service-overview ul.list { padding: 0px; margin: 0px; margin-left: 15px; list-style-type: none; }
div.service-overview ul.list li { font-size: 1.1em; }
div.service-description { padding: 15px; padding-bottom: 0px; }
div.service-description div.title { font-weight: bold; font-size: 1.2em; }
div.service-description p.doc-lines { font-size: 0.8em; }
div.service-description p.url { font-size: 0.8em; font-style: italic; }
div.service-description p.url span.url-title { font-weight: bold; }
div.service-interfaces { padding: 15px; padding-bottom: 0px; }
div.service-interfaces div.title { font-weight: bold; font-size: 1.2em; }
div.service-interfaces ul.list { font-size: 0.8em; }
div.service-interfaces ul.list li { padding: 4px; }
div.service-api { padding: 15px; padding-bottom: 0px; }
div.service-api div.methods div.title { font-weight: bold; font-size: 1.2em; }
div.service-api div.methods ul.list { font-size: 0.9em; list-style-type: none; }
div.service-api div.methods ul.list li.entry {
-moz-border-radius: 7px 7px 7px 7px; -webkit-border-radius: 7px 7px 7px 7px; border-radius: 7px 7px 7px 7px; background-color: #F6F6F6; border: 1px solid #E6E6E6;
border-collapse: separate; font-size: 0.8em; padding: 10px; margin-right: 20px;
-moz-box-shadow: 2px 2px 5px #555; -webkit-box-shadow: 2px 2px 5px #555; box-shadow: 2px 2px 5px #555;
margin-bottom: 16px;
}
div.service-api div.methods ul.list li.entry div.declaration {
font-size: 1.5em;
}
div.service-api div.methods ul.list li.entry div.declaration span.name { color: #881a1a; }
div.service-api div.methods ul.list li.entry span.param-type { color: #68387f; }
div.service-api div.methods ul.list li.entry span.param-name {}
div.service-api div.methods ul.list li.entry p.doc-lines { font-size: 1.2em; color: #276d11; }
div.service-api div.methods ul.list li.entry ul.params p.doc-lines { margin-top:0;margin-bottom:6px; font-size: 1.0em; color: #276d11; }
div.service-api div.types div.title { font-weight: bold; font-size: 1.2em; }
div.service-api div.types ul.list { font-size: 0.9em; list-style-type: none; }
div.service-api div.types ul.list li.entry {
-moz-border-radius: 7px 7px 7px 7px; -webkit-border-radius: 7px 7px 7px 7px; border-radius: 7px 7px 7px 7px; background-color: #F6F6F6; border: 1px solid #E6E6E6;
border-collapse: separate; font-size: 0.8em; padding: 10px; margin-right: 20px;
-moz-box-shadow: 2px 2px 5px #555; -webkit-box-shadow: 2px 2px 5px #555; box-shadow: 2px 2px 5px #555;
margin-bottom: 16px;
}
div.service-api div.types ul.list li.entry div.definition {
font-size: 1.5em;
}
div.service-api div.types ul.list li.entry div.definition span.name { color: #881a1a; }
div.service-api div.types ul.list li.entry span.param-type { color: #68387f; }
div.service-api div.types ul.list li.entry span.param-name {}
div.service-api div.types ul.list li.entry p.doc-lines { margin-top:0;margin-bottom:6px; font-size: 1.0em; color: #276d11; }
div.service-footer { font-size: 0.8em; text-align: center; font-style: italic; padding-top: 10px; padding-bottom: 10px; }
a:link { color: #00732F; text-decoration: none }
a:visited { color: #00732F; text-decoration: none }
a:hover { color: #00732F; text-decoration: underline }
</style>
</head>
<body>
<div class="service-header">
<div class="service-title">Calculator</div>
<form method="get" class="skin-selector">
<label for="skin-select">skins:</label>
<select id="skin-select" name="skin" onchange="document.forms[0].submit()">
<option value="">Default</option>
<option value="simple">Simple</option>
<option value="bluebox">Bluebox</option>
</select>
</form>
</div>
<div class="service-overview">
<div class="headline">Overview</div>
<div class="title">Methods</div>
<ul class="list">
<li>
<span class="entry">add</span>
( )
</li>
</ul>
<div class="title">Types</div>
<ul class="list">
</ul>
</div>
<div class="service-description">
<div class="title">Description</div>
<p class="doc-lines">
This service does the math, and serves as example for new potential Ladon users.
</p>
</div>
<div class="service-interfaces">
<div class="title">Interfaces</div>
<ul class="list">
<li>soap11 [ url description ]</li>
<li>jsonwsp [ url description ]</li>
<li>soap [ url description ]</li>
</ul>
</div>
<div class="service-api">
<div class="methods">
<div class="title">Methods</div>
<ul class="list">
<li class="entry">
<div class="declaration">
<a name="add"></a><span class="name">add</span>
(
<span class="param-type">
number
</span>
<span class="param-name">a</span>
,
<span class="param-type">
number
</span>
<span class="param-name">b</span>
)
</div>
<p class="doc-lines">
Add two integers together and return the result
</p>
<div class="params-title">Parameters</div>
<ul class="params">
<li>
<span class="param-name">a</span>: <span class="param-type">
number
</span>
<br/>
<p class="doc-lines">
1st integer
</p>
</li>
<li>
<span class="param-name">b</span>: <span class="param-type">
number
</span>
<br/>
<p class="doc-lines">
2nd integer
</p>
</li>
</ul>
<div class="return-type-title">Return value</div>
<div class="return-type">
<span class="param-type">
number
</span>
<p class="doc-lines">
The result of the addition
</p>
</div>
</li>
</ul>
</div>
<div class="types">
<div class="title">Types</div>
<ul class="list">
</ul>
</div>
</div>
<div class="service-footer">Powered by Ladon for Python</div>
</body>
</html>
It looks like the URL path you are using is wrong and should be changed to http://ladonize.org/python-demos/Calculator/jsonwsp.
A better way to create jsonData would be using dataUsingEncoding:.
You shouldn't be creating a response:
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
Because it will be created and returned to you as part of the sendSynchronousRequest. What you should be doing is checking the contents of theResponse to verify the HTTP status code.
This is working solution...
NSString *requestString = [NSString stringWithFormat:
#"http://ladonize.org/python-demos/Calculator/jsonwsp"];
NSString *jsonString = [NSString stringWithFormat:#"{\"methodname\":\"add\",\"args\": {\"a\":123,\"b\":123}}"];
//: {"methodname": "add", "args": {"a":"123","b":"123"}}
NSLog(#"the request string is %#", requestString);
NSData *jsonData = [NSData dataWithBytes: [jsonString UTF8String] length: [jsonString length]];
NSURL *url = [NSURL URLWithString:requestString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"POST"];
[request setHTTPBody: jsonData];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
[request setValue:[NSString stringWithFormat:#"%d", [jsonData length]] forHTTPHeaderField:#"Content-Length"];
NSError *errorReturned = nil;
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&errorReturned];
if (errorReturned) {
NSLog(#"Error %#",errorReturned.description);
}
else
{
NSError *jsonParsingError = nil;
NSMutableArray *arrDoctorInfo = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments error:&jsonParsingError];
NSString* newStr = [NSString stringWithUTF8String:[data bytes]];
NSLog(#"Dict %#",newStr);
}

Categories